Testing connectivity
Once your network interfaces and DNS are configured, its important to verify that your system can reach other machines and the internet. This section covers the essential tools for beginners.
Checking Basic Connectivity with ping
The ping command sends ICMP echo requests to a host to see if it responds.
shellsession
user@machine:~$ ping 8.8.8.8
64 bytes from 8.8.8.8: icmp_seq=1 ttl=114 time=6.97 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=114 time=6.99 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 6.970/6.980/6.991/0.010 ms- Sends packets to Google’s public DNS server.
- Press
Ctrl + Cto stop otherwise it will repeatedly ping. - Success indicates your network interface is working and you can reach the target IP.
You can also test DNS resolution.
shellsession
user@machine:~$ ping example.com
PING example.com (104.18.26.120) 56(84) bytes of data.
64 bytes from 104.18.26.120: icmp_seq=1 ttl=55 time=8.48 ms
^C
--- example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 8.475/8.475/8.475/0.000 m
- Ensures your DNS server is translating domain names into IPs.
Checking Routes with ip route
Sometimes you can’t reach a host due to routing issues. Check your routing table.
shellsession
user@machine:~$ ip route show
default via 172.29.16.1 dev eth0 proto kernel
172.29.16.0/20 dev eth0 proto kernel scope link src 172.29.26.129default via <IP>-> Your default gateway- Local network routes show which IPs are reachable directly.
Tracing the Path with traceroute
Note that this may not come built into linux.
traceroute(or tracepath) shows the route packets take to reach a host.
shellsession
user@machine:~$ tracepath example.com # For this example, I will be using tracepath instead of traceroute as I do not have that installed. Do note they essentially provide the same information.
1?: [LOCALHOST] pmtu 1500
1: 172.29.16.1 0.482ms
1: 172.29.16.1 0.534ms
2: 192.168.28.1 1.946ms
3: 192.168.18.1 3.332ms
4: 1.64.212.218.starhub.net.sg 8.209ms
5: 183.90.44.201 37.261ms
6: no reply
7: no reply
8: 203.118.6.126 7.150ms
9: 162.158.160.230 8.434ms asymm 10
10: 172.69.117.39 6.354ms
11: 172.69.117.103 8.728ms asymm 10
12: no reply
13: no reply
14: no reply
15: no reply
16: no reply
17: no reply
18: no reply
19: no reply
20: no reply
21: no reply
22: no reply
23: no reply
24: no reply
25: no reply
26: no reply
27: no reply
28: no reply
29: no reply
30: no reply
Too many hops: pmtu 1500
Resume: pmtu 1500- You may notice that some entries say “no reply”. This is because the server blocks ICMP requests but allows normal network traffic to pass through.
- After 30 hops, the
tracepathcommand returns.
Checking Port Connectivity with nc (optional)
nc (netcat) can test if a service on a host is reachable. If available, netcat connects to the host on the specified port.
shellsession
nc -zw example.com 80-z-> just scan without sending data-v-> verbose output- Tests if port 80 (HTTP) is reachable.
It is more recommended to use ping instead general network connectivity testing.
Summary
- Use
pingto check if hosts/IPs are reachable. - Use
ip route showto verify routing.