Testing Network Connectivity
Network connectivity testing is essential for diagnosing and resolving network issues. Various tools and commands can help verify the status and performance of network connections. Below is a comprehensive guide to testing network connectivity.
Basic Connectivity Tests
ping:
- Used to check if a remote host is reachable and measure round-trip time for packets.
 
Example:
shping -c 4 example.comOutput:
plaintextPING example.com (93.184.216.34): 56 data bytes 64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=15.2 ms 64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=14.9 ms 64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=15.0 ms 64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=15.1 ms --- example.com ping statistics --- 4 packets transmitted, 4 packets received, 0.0% packet losstraceroute:
- Traces the path packets take to reach a remote host.
 
Example:
shtraceroute example.comOutput:
plaintexttraceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets 1 192.168.1.1 (192.168.1.1) 1.153 ms 1.166 ms 1.159 ms 2 10.0.0.1 (10.0.0.1) 9.254 ms 9.270 ms 9.264 ms 3 example.com (93.184.216.34) 15.265 ms 15.278 ms 15.272 msnslookup and dig:
- Query DNS to resolve domain names to IP addresses and vice versa.
 
nslookup Example:
shnslookup example.comOutput:
plaintextServer: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: Name: example.com Address: 93.184.216.34dig Example:
shdig example.comOutput:
plaintext; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22606 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; QUESTION SECTION: ;example.com. IN A ;; ANSWER SECTION: example.com. 299 IN A 93.184.216.34 ;; Query time: 23 msec ;; SERVER: 192.168.1.1#53(192.168.1.1) ;; WHEN: Wed Jun 12 10:20:23 UTC 2024 ;; MSG SIZE rcvd: 56
Advanced Connectivity Tests
telnet and nc (netcat):
- Check if specific ports on a remote host are open.
 
telnet Example:
shtelnet example.com 80Output:
plaintextTrying 93.184.216.34... Connected to example.com. Escape character is '^]'.netcat (nc) Example:
shnc -zv example.com 80Output:
plaintextConnection to example.com 80 port [tcp/http] succeeded!ifconfig and ip:
- Display and configure network interfaces.
 
ifconfig Example:
shifconfigOutput:
plaintexteth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a00:27ff:fe4e:66a prefixlen 64 scopeid 0x20<link> ether 08:00:27:4e:66:6a txqueuelen 1000 (Ethernet) RX packets 156 bytes 20526 (20.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 148 bytes 19582 (19.5 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ip Example:
ship addrOutput:
plaintext2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:4e:66:6a brd ff:ff:ff:ff:ff:ff inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe4e:66a/64 scope link valid_lft forever preferred_lft foreverethtool:
- Display or change Ethernet device settings.
 
Example:
shsudo ethtool eth0Output:
plaintextSettings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on MDI-X: Unknownmtr:
- Combines the functionality of 
pingandtracerouteto diagnose network issues. 
Example:
shmtr example.comOutput:
plaintextStart: 2024-06-12T10:20:23+0000 HOST: hostname Loss% Snt Last Avg Best Wrst StDev 1. 192.168.1.1 0.0% 10 0.4 0.4 0.4 0.5 0.0 2. 10.0.0.1 0.0% 10 9.2 9.3 9.2 9.4 0.0 3. example.com 0.0% 10 15.1 15.0 14.9 15.1 0.0- Combines the functionality of 
 
Example Scenario
Diagnosing Network Connectivity Issue:
Ping the Gateway:
shping -c 4 192.168.1.1Traceroute to an External Host:
shtraceroute 8.8.8.8Check DNS Resolution:
shnslookup example.comVerify Interface Configuration:
ship addr show eth0Check Ethernet Device Settings:
shsudo ethtool eth0Diagnose with mtr:
shmtr 8.8.8.8
Summary
Testing network connectivity involves using a combination of tools to diagnose and resolve issues. Basic commands like ping, traceroute, nslookup, and dig help verify connectivity and DNS resolution. Advanced tools like telnet, netcat, ifconfig, ip, ethtool, and mtr provide deeper insights into network configurations and performance. By systematically using these tools, you.