Checking Network Connectivity
A good way to check for network connectivity is by using the ping command. The basic syntax of the command expects a host to be specified.
root@hostname:directory# ping 192.168.1.144
This command sends data in the form of packets and listens for returned packets. By checking the number and percentage of packets returned, you can gauge the quality and response of the network connection. Note that you need to interrupt the output of ping using <Ctrl>+C so that the prompt returns.
If you have a LAN, you may want to first check whether you are connected to your local gateway. As an example, check the following output:
root@hostname:directory# ping 192.168.1.5 PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data. 64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=3.02 ms 64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=0.244 ms 64 bytes from 192.168.1.5: icmp_seq=3 ttl=64 time=0.232 ms <Ctrl>+C --- 192.168.1.5 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 0.232/1.167/3.026/1.314 ms demo:/var/easypush/etc#
As we see above, a number of lines are printed on the screen. Each line represents a packet sent to the host and returned back. The time taken for the round trip is shown, along with some summary statistics. If there is no network connection, an output similar to the following appears:
root@hostname:directory# ping 192.168.1.5 PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data. --- 192.168.1.5 ping statistics --- 3 packets transmitted, 0 received, 100% packet loss, time 2008ms demo:/var/easypush/etc#
The message "0 received, 100% packet loss" indicates that the network link to the given host could possibly be broken.
deepOfix provides ethtool, a command with a simple syntax and high utility. It checks the ethernet interface as argument which you specify as argument.
root@hostname:directory# ethtool eth0 Settings for eth0: Supported ports: [ TP MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: MII PHYAD: 1 Transceiver: internal Auto-negotiation: on Supports Wake-on: pg Wake-on: d Current message level: 0x000000c5 (197) Link detected: yes root@hostname:directory#
In above output, "Link detected: yes" indicates that the network interface eth0 is up.
The traceroute command traces the path of a packet sent to a particular host. It lists sequentially, each gateway involved in transferring a packet to the host specified as argument. This is useful to check your connection to systems outside a LAN. You can use it to check connectivity to the Internet.
root@hostname:directory# traceroute www.iisc.ernet.in traceroute to www.iisc.ernet.in (184.108.40.206), 30 hops max, 40 byte packets 1 192.168.1.5 (192.168.1.5) 0.192 ms 0.135 ms 0.109 ms 2 * * dsl-KK-static-001.192.95.61.airtelbroadband.in (220.127.116.11) 35.138 ms 3 dsl-KK-static-18.104.22.168.airtelbroadband.in (22.214.171.124) 41.928 ms 50.485 ms 39.671 ms 4 126.96.36.199 (188.8.131.52) 41.348 ms 40.454 ms 47.524 ms 5 184.108.40.206 (220.127.116.11) 41.382 ms 51.414 ms 45.801 ms 6 18.104.22.168 (22.214.171.124) 50.166 ms 53.345 ms 54.707 ms 7 126.96.36.199 (188.8.131.52) 46.609 ms 47.190 ms 49.362 ms 8 184.108.40.206 (220.127.116.11) 230.985 ms 235.826 ms 204.620 ms 9 18.104.22.168 (22.214.171.124) 75.458 ms 72.554 ms 72.951 ms 10 126.96.36.199 (188.8.131.52) 69.662 ms 78.223 ms 70.749 ms 11 184.108.40.206 (220.127.116.11) 71.362 ms 75.862 ms 269.194 ms <Ctrl>+C root@hostname:directory#
Since we are looking to check Internet connection, we can break by pressing <Ctrl>+C once we find external IP addresses appearing in the output listing. If the connection is slow, ping can be used too.