- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Checking Host’s Network Availability in Linux
When working with Linux systems, it is important to be able to check the network availability of a specific host. This can be useful for troubleshooting connectivity issues, monitoring network performance, or simply checking the status of a specific server or device. In this article, we will discuss several methods for checking the network availability of a host in Linux.
Ping Command
The most basic method for checking network availability is to use the ping command. This command sends an Internet Control Message Protocol (ICMP) echo request packet to the specified host and waits for a response. If the host is online and responding, it will send an echo reply packet. To use the ping command, simply open a terminal and type "ping" followed by the hostname or IP address of the host you wish to check. For example, to check the availability of the Google server, you would type "ping google.com".
The "ping" command is used to test the reachability of a host on a network. The basic syntax for using the ping command is −
ping [hostname or IP address]
For example, to ping the host "www.example.com", you would run the command −
ping www.example.com
or
ping 192.168.1.1
You should see output that looks like this −
PING www.example.com (93.184.216.34) 56(84) bytes of data. 64 bytes from 93.184.216.34: icmp_seq=1 ttl=57 time=14.9 ms 64 bytes from 93.184.216.34: icmp_seq=2 ttl=57 time=14.9 ms 64 bytes from 93.184.216.34: icmp_seq=3 ttl=57 time=14.9 ms
This output shows that the host is reachable, as it has replied to the ping request. If the host is not reachable, the output will look like this −
ping: www.example.com: Name or service not known
You can also specify the number of times the ping should be sent by using -c option
ping -c 5 www.example.com
This command will send 5 ping request to the host.
You can use -i option to set the interval between sending ping requests
ping -i 2 www.example.com
This command will send the ping requests with 2 seconds interval between each request.
You can also use -W option to set the timeout for ping response
ping -W 3 www.example.com
This command will wait for 3 seconds for the response after sending the request.
Traceroute Command
Another useful command for checking network availability is the traceroute command. This command sends a series of ICMP echo request packets to the specified host, and tracks the path that the packets take to reach the host. This can be useful for determining the cause of connectivity issues, as it can show which routers or networks are causing problems. To use the traceroute command, simply open a terminal and type "traceroute" followed by the hostname or IP address of the host you wish to check. For example, to check the route to the Google server, you would type "traceroute google.com".
The "traceroute" command is used to show the route that a packet takes to reach a host, including any intermediate routers. The basic syntax for using the traceroute command is −
traceroute [hostname or IP address]
For example, to trace the route to the host "www.example.com", you would run the command −
traceroute www.example.com
or
traceroute 192.168.1.1
You should see output that looks like this −
traceroute to www.example.com (93.184.216.34), 30 hops max, 60 byte packets 1 192.168.1.1 (192.168.1.1) 2.049 ms 1.892 ms 1.874 ms 2 10.1.1.1 (10.1.1.1) 9.938 ms 9.874 ms 9.834 ms 3 10.1.1.2 (10.1.1.2) 20.8 ms 20.724 ms 20.684 ms 4 93.184.216.34 (93.184.216.34) 14.9 ms 14.844 ms 14.804 ms
This output shows the route that the packets take to reach the destination host. Each line represents a "hop" in the route. The IP address or hostname of the router is shown, along with the time it took for the packet to reach that router.
You can also specify the maximum number of hops to trace by using the -m option −
traceroute -m 20 www.example.com
This command will trace the route up to 20 hops.
Netstat Command
The netstat command can also be used to check network availability. This command shows various network statistics, including the status of network connections, the routing table, and network interfaces. To check the network availability of a specific host using the netstat command, you can use the "-n" option to display IP addresses and ports, and the "-r" option to display the routing table. For example, to check the routing table for the host "google.com", you would type "netstat -nr | grep google.com".
The "netstat" command is used to display various network-related information on a Linux system, including active network connections, routing tables, and network interface statistics.
To check for active network connections, you can use the following command −
netstat -tuln
This command will show all active TCP connections and the process ID (PID) of the program that owns the connection. The "-t" option shows TCP connections, the "-u" option shows UDP connections, the "-l" option shows only listening sockets, and the "-n" option shows numerical addresses rather than resolving hostnames.
You can also check for a specific protocol and port by using the following command −
netstat -tuln | grep ":80"
This command will show all TCP connections that are listening on port 80.
To check the routing table, you can use the following command −
netstat -r
This command will show the routing table, including the destination, gateway, and netmask for each route.
Nmap Command
Another useful tool for checking network availability is the nmap command. This command is a network scanner that can be used to check the availability of hosts, ports, and services on a network. To use the nmap command, simply open a terminal and type "nmap" followed by the hostname or IP address of the host you wish to check. For example, to check the availability of the Google server, you would type "nmap google.com".
The "nmap" command is used to scan a host or network for open ports, running services, and other information. The basic syntax for using the nmap command is −
nmap [hostname or IP address]
For example, to scan the host "www.example.com", you would run the command −
nmap www.example.com
or
nmap 192.168.1.1
You should see output that looks like this −
Starting Nmap 7.80 ( https://nmap.org ) at 2020-11-23 13:00 EST Nmap scan report for www.example.com (93.184.216.34) Host is up (0.11s latency). Not shown: 998 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp open https
This output shows the open ports and the services running on those ports on the destination host.
You can also use -A option to enable OS and version detection, script scanning and traceroute
nmap -A www.example.com
This command will enable OS and version detection, script scanning and traceroute.
Conclusion
There are several methods for checking the network availability of a host in Linux. The ping, traceroute, netstat, and nmap commands are all useful tools for troubleshooting connectivity issues, monitoring network performance, or simply checking the status of a specific server or device. By using these commands, you can easily check the network availability of a host and take the necessary steps to resolve any issues that may arise.