Ping server from linux

15+ ping command examples in Linux [Cheat Sheet]

ping (Packet Internet Groper) is a command-line utility in Linux to check the network connectivity between host and host/server. It also helps to test, diagnose, and troubleshoot network connectivity issues. With the ping command, you can know if a server is up and running. The ping sends ICMP (Internet Control Message Protocol) ECHO_REQUEST messages to the specified host and waits for the reply. If the host is available, it sends an ICMP echo reply message (ECHO_RESPONSE). If ping does not receive any reply packets, it will exit with code 1.

Syntax to use ping command

The syntax for the ping command is:

Some options available in the ping command are given below.

Different examples to use ping command in Linux

1. ping command to check the network connectivity of target host

You can run the ping command without any option to check if the server of the target host is up and running. For example, to test our website, you can use the website name or IP address.

Sample Output:

ping command to check the network connectivity of the target host

You need to press Ctrl+C to stop the ping otherwise it will keep sending the packets infinitely. DUP! are the duplicate packets caused by inappropriate link-level retransmissions.

2. Specify the number of pings to be performed with ping command

When you specify the count N, the ping command stops sending the packets after N replies. You do not have to stop the ping with Ctrl+C.

Sample Output:

ping command to specify the count

3. Check localhost network with ping command

You can ping localhost to check if you have a network connection.

Sample Output:

ping command to check local network

4. Set interval seconds between sending each packet with ping command

The -i option set interval time in seconds to wait before sending each packet. The default is to wait for one second between each packet, or not to wait in flood mode.

Sample Output:

ping command to wait interval seconds between sending each packet

5. Perform flood ping towards target host

The -f option is used to run the flood ping. In flood ping, for every ECHO_REQUEST sent a period ».» is printed, and for every ECHO_REPLY received a backspace is printed. The interval time is zero and the packets are sent one hundred times per second. Only the super-user can use this option with zero intervals.

Читайте также:  Linux режим работы сетевой карты

Sample Output:

ping command to flood the networks

6. Specify the number of data bytes to be sent with ping command

The -s option specifies the number of data bytes to be sent. The default size is 56 ICMP data bytes which become 64 bytes when combined with the 8 bytes of ICMP header data.

Sample Output:

ping command to specify the number of data bytes

7. Display only the summary lines for ping command output

The -q option can be used to display only the summary lines at startup time and when finished.

Sample Output:

ping command to display only the summary lines

8. Set special IP timestamp options

The -T option sets special IP timestamp options. timestamp option can be:

  • tsonly: only timestamps
  • tsandaddr: timestamps and addresses
  • tsprespec host1 [host2 [host3 [host4]]]: timestamp prespecified hops

Sample Output:

ping command to set timestamp option

9. Specify the timeout in seconds for ping command

The -w option specifies a ( timeout in seconds) before ping exits regardless of how many packets have been sent or received. ping waits for the reply in seconds.

Sample Output:

ping command to specify the timeout in seconds

10. Set time to wait for a response for ping command

The -W option is used to set the time to wait for a response, in seconds. The option affects only timeout in absence of any responses otherwise, ping waits for two RTTs (round-trip time).

Sample Output:

ping command to set time to wait for a response

11. Send multiple packets while waiting for replies with ping command

The -l option specifies the number of packets that are to be sent while waiting for replies. Only the super-user can select preload more than 3.

Sample Output:

ping command to send many packets while waiting for replies

12. Set the IP time to live with ping command

You can use -t option to set the IP time to live (TTL). It limits the number of network hops. The value ranges between 1 and 255.

Sample Output:

ping command to set time to live

13. Print timestamps with ping command

The -D option prints the timestamps before every line.

Sample Output:

ping command to print timestamps

14. Use IPv4 or IPv6 address with ping command

The -4 and -6 options are used to specify the IPv4 and IPv6 addresses respectively.

Sample Output:

ping command to use ipv4 address

When you use the IPv6 address with -4 option, it shows an error message.

ubuntu@golinux:~$ ping -4 2606:4700::6813:9a5c ping: 2606:4700::6813:9a5c: Address family for hostname not supported

15. Perform audible ping

When the -a option is used, the system will produce a sound if there is a reply from the host.

Sample Output:

ping command to use audible ping

16. Report ICMP ECHO reply for ping command

The -O option reports outstanding ICMP ECHO reply before sending the next packet. It is useful together with the -D option to log
output to a diagnostic file and search for missing answers.

Sample Output:

ping command to report reply before sending next packet

17. Print full user-to-user latency with ping command

Normally, ping prints network round trip time which can be different, for example, due to DNS failures. The -U option can be used to print full user-to-user latency.

Sample Output:

ping command to print full user-to-user latency

Conclusion

This tutorial teaches you to use ping command with different options in a Linux system. ping is a useful tool that allows you to test the connectivity of a specified host on the network. If you still have any confusion, please let us know in the comment section.

Источник

How to ping IP and port from Windows or Linux

One of the things I do the most when troubleshooting deployments of services exposing data to the internet is pinging the IP and port where the service is supposed to be alive. In this tutorial, I will show you how to ping IP and port on Linux and Windows.

Читайте также:  Linux list all user and group

I think most system administrators know the commands for this, but if you like me normally don’t work like an IT admin (at least not anymore) I tend to forget the commands. Due to that, I have written this article as a reference for myself but also for everyone else, who is in need of pinging services they expect at a location.

Often it’s enough to just ping an IP to validate that you got “life” on the server. However if you like me often got many services running on one server (often when using Docker), I need to ping the specific port number on the server. One of the Kubernetes clusters I manage is running more than 100 services and here I use it a lot.

In this article/reference post, I will show you how to ping IP and port on your Windows or Linux machine using different commands in the terminal (CLI).

Ping IP and port using Telnet

This is my favorite when working on both Windows and Linux. I also think that it’s the easiest one to use and it’s called Telnet. You can with a simple command using Telnet ping IP and port on the remote server you would like to check.

If you want to, you can also use a domain instead of the IP. A domain is often easier for humans to remember instead of numbers to multiple different servers locally or externally.

Below are the commands to ping IP and port on a server using Telnet:

As I mentioned above, you can use Telnet on both Windows and Linux computers/servers which makes it a great choice for most sys-ops.

On most computers, telnet is not installed by default. If you get the annoying error “telnet: command not found”, you have to install Telnet on the machine using the commands below:

Install Telnet on Linux

If you are working on a Linux Server or Desktop, you can use the below command to install Telnet on that machine:

Install Telnet on Windows

By default, Telnet is not an enabled Windows Feature. If you run Telnet on your computer in a Command Prompt, you will get the following error: “Telnet is not recognized as an operable program or batch file.”. So – to install Telnet on Windows, you have to do the following:

  1. Click on Start.
  2. Select Control Panel.
  3. Choose Programs and Features.
  4. Click Turn Windows features on or off.
  5. Select the Telnet Client option.
  6. Click OK.
    A dialog box appears to confirm installation when it’s done. The telnet command should now be available in your Command Prompt. Remember to restart your CMD window.

Ping IP and port with Telnet example

Let’s check out how Telnet works. This website is running at IP: 172.67.161.26 – this is the public IP address of the website to which the domain is mapped to.

By default, all requests are redirected to HTTPS (port 443) if a request is made at port 80. This means that the server accepts connections on port 80 too – let’s try and ping both ports:

$ telnet 172.67.161.26 80 Trying 172.67.161.26. Connected to 172.67.161.26. Escape character is '^]'. $ telnet 172.67.161.26 443 Trying 172.67.161.26. Connected to 172.67.161.26. Escape character is '^]'.

That went well. We got connected and could see that the server is responding on both ports. This simply means that the service on the port is up and running.

If you would like to escape out of the Telnet utility when connected, you can use “CTRL + ] ” or the “q” command.

Ping IP and port using Nmap

Another well-used tool is Nmap. In Nmap, you can ping a port by using the “-p” option including the IP or domain you would like to scan.

Читайте также:  Linux bash if eval

A heads up – be aware of legal issues!

“When used properly, Nmap helps protect your network from invaders. But when used improperly, Nmap can (in rare cases) get you sued, fired, expelled, jailed, or banned by your ISP.” – Nmap website.

If you get an error telling you that Nmap is not available on your computer/server, you would have to install it.

Install Nmap on Linux

To install Nmap on your Linux machine, you can use the below command:

Install Nmap on Windows

Not as simple as Linux, but it’s still easy to use the official installer from Nmap’s website. Go to this page: Download Nmap and look under the Windows Binaries for the latest available installer file.

Once the installer has completed installing, you are now ready to use Nmap on your Windows computer.

Ping IP and port using Nmap

Let’s try to ping a website at IP “172.67.161.26” on the global internet at the default HTTPS port – 443. If you test this yourself, then don’t use that IP. Cloudflare is protecting the website and will block your access and in the worst-case ban your IP from their global network. Only do this at IPs you own or services that won’t do any damage to others.

C:\Users\christian>nmap -p 443 172.67.161.26 Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-10 06:50 Romance Standard Time Nmap scan report for 172.67.161.26 Host is up (0.028s latency).

Well, once again the port is returned as open on the server. This means that there is a service accepting data at port 443, which was just verified by Nmap.

Ping IP and port using PowerShell

Normally when I’m not on my own machines, which means I’m working on production servers not related to my own business/platform and it’s a Windows Server Environment, I always use PowerShell to ping IP and port.

A great thing about PowerShell is that you can use the methods in scripts running automated stuff in the background or during the setup of service or multiple services. A great thing if deploying with PowerShell would be to check if the ports were active after deployment and return a status to the terminal.

In PowerShell, we got something called Test-NetConnection which is a command where you specify either an IP or a domain followed by the port you would like to ping.

PS C:\Users\christian> Test-NetConnection -p

Below is an example of what this would look like on a local network:

Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\Users\christian> Test-NetConnection 192.168.1.1 -p 80 ComputerName : 192.168.1.1 RemoteAddress : 192.168.1.1 RemotePort : 80 InterfaceAlias : Wi-Fi SourceAddress : 192.168.1.68 TcpTestSucceeded : True

In the test above you can see that the TCP call to my gateway at home succeeded at port 80. If you can’t get through to the service you will status False in TcpTestSucceeded.

Summary

In this quick article on how to ping IP and port using different tools on Windows or Linux machines, we learned how we can use the terminal to check if a given port is open and accepting requests.

If you got any issues, questions, or suggestions, please let me know in the comments below. Happy pinging!

Christian Schou

My name is Christian. I am a 27-year-old pragmatic software engineer with a passion for .NET, Cloud, and Containers. In my spare time, I share my knowledge and love teaching other people about tech.

Источник

Оцените статью
Adblock
detector