🌐 🇵🇱 Polski · 🇬🇧 EN
A key element of network troubleshooting is ensuring that everything is configured correctly and that the entire network is functioning as expected. Here, I will show you five quick commands that will help you verify network health.
- ping - Test connectivity between two hosts
- traceroute - Shows the path taken to connect two hosts
- netstat - Displays information about connections (open, closed, and listening)
- route - Displays routing table information
Up to this point, most exercises were performed on only one machine in our laboratory, namely RHEL01. The main reason for this is that the other machines are located inside a private network and cannot be accessed from the outside. For now, everything is fine because RHEL01, as the host, has two network interfaces allowing it to exist in two networks. We can see how these machines interact with each other in the private network.
NETWORK TOOLS
We will start with the "ping" command to check if hosts can see each other on the network.
Ping command syntax: # ping [target, hostname, IP]
Unlike in Windows systems, the command executed in Linux will run until it is interrupted by the user. You can, of course, specify how many times it should run by using the "-c" flag.
Step 1 - Check if RHEL01 can see RHEL02 on the network
PING 172.168.1.2 (172.168.1.2) 56(84) bytes of data.
64 bytes from 172.168.1.2: icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from 172.168.1.2: icmp_seq=2 ttl=64 time=0.074 ms
Step 2 - Check if RHEL01 has access to the external network via the gateway.
# ping –c 2 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.074 ms
Communication works both ways, meaning access to the outside world and the internal network is possible. Let's check the same on the RHEL02 machine.
Step 1 - Check communication from RHEL02 to RHEL01
# ping –c 2 172.168.1.1
PING 172.168.1.1 (172.168.1.1) 56(84) bytes of data.
64 bytes from 172.168.1.1: icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from 172.168.1.1: icmp_seq=2 ttl=64 time=0.074 ms
As you can see, both machines can communicate with each other, and RHEL01 can communicate with the external network. What happens if we try to connect to the 192.168.1.0 address from RHEL02?
Step 2 - Let's check the connection to the outside world from RHEL02
# ping –c 2 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
From 172.168.1.1 icmp_seq=2 Destination Host Unreachable
From 172.168.1.1 icmp_seq=3 Destination Host Unreachable
This machine cannot connect to the gateway and receives a "Destination Host Unreachable" message. This message means that no route has been set for RHEL02 to the 192.168.1.0 network. What routes are available then? Let's check!
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.168.1.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
As you can see, we only have traffic within the 172.168.1.0 network, which is the reason blocking communication with 192.168.1.0.
Now that we know how to check interfaces and routes, it would be good to see open ports and services listening on specific ports. For this purpose, we will use the "netstat" command.
Netstat command syntax: # netstat [options]
Netstat command options:
- -r - Displays the routing table
- -I - Displays interface statistics
- -t - Shows tcp connections
- -u - Shows udp connections
- -a - Shows sockets (tcp, udp, and local)
- -p - Shows process IDs
- -e - Shows extended information
For example, let's assume we want to find out if the SSH service is listening on the correct port 22.
# netstat -tuape | grep ssh
tcp 0 0 *:ssh *:* LISTEN root 8627 2674/sshd
If nothing is displayed, there is a high chance that the service has not been started at all. This command is an excellent aid for troubleshooting network issues in Linux.
Comments