19.2. Testing Connectivity with ping Problem

Some services or hosts on your network are not accessible, or have intermittent failures. You don't know if it's a physical problem, a problem with name services, routing, or what the heck. Where do you start?

Good old ping should always be your first stop. Use the -c switch to limit the number of pings; otherwise, it will run until you stop it with Ctrl-C:

	$ ping localhost
	PING xena.alrac.net (127.0.1.1) 56(84) bytes of data.
	64 bytes from xena.alrac.net (127.0.1.1): icmp_seq=1 ttl=64 time=0.034 ms
	64 bytes from xena.alrac.net (127.0.1.1): icmp_seq=2 ttl=64 time=0.037 ms
	--- xena.alrac.net ping statistics ---
	2 packets transmitted, 2 received, 0% packet loss, time 999ms
	rtt min/avg/max/mdev = 0.034/0.035/0.037/0.006 ms

Pinging localhost first confirms that your network interface is up and operating. You can also ping your hostname and IP address to further confirm that local networking is operating correctly. Then, you can test other hosts:

	$ ping -c10 uberpc
	PING uberpc.alrac.net (192.168.1.76) 56(84) bytes of data.
	64 bytes from uberpc.alrac.net (192.168.1.76): icmp_seq=1 ttl=64 time=5.49 ms
	[...]

	--- uberpc.alrac.net ping statistics ---
	10 packets transmitted, 10 received, 0% packet loss, time 9031ms
	rtt min/avg/max/mdev = 0.097/0.108/0.124/0.007 ms

The output from that simple command gives you several useful pieces of information, including that name resolution is working and you have a good, clean, fast connection.

This example shows a problem:

	$ ping -c10 uberpc
	ping: unknown host uberpc

This means you entered the wrong hostname, DNS is broken, routing is goofed up, or the remote host is not connected to the network. So, your next step is to ping the IP address:

	$ ping -c10 192.168.1.76
	PING 192.168.1.76 (192.168.1.76) 56(84) bytes of data.
	From 192.168.1.10 icmp_seq=1 Destination Host Unreachable
	[...]
	From 192.168.1.10 icmp_seq=10 Destination Host Unreachable

	--- 192.168.1.76 ping statistics ---
	10 packets transmitted, 0 received, +9 errors, 100% packet loss, time 9011ms
	, pipe 3

This shows that you entered the wrong IP address or the host is down, but you got as far as a router on the host's network. You know this because the router sent you the "Destination Host Unreachable" message.

If pingingr the IP address had succeeded, then that would point to a DNS problem.

This is what it looks like when your own PC is not connected to the network:

	$ ping -c10 192.168.1.76
	connect: Network is unreachable

This is what you see when the whole remote network is unreachable:

	$ ping -c10 alrac.net
	PING alrac.net(11.22.33.44) 56(84) bytes of data.
	--- alrac.net ping statistics ---
	10 packets transmitted, 0 received, 100% packet loss, time 10007ms

If the failure is intermittent, increase the number of pings to several hundred. It's a good idea to place a limit because we do go off and forget that it's running.

When the hosts that you are pinging are on the other side of your router or Internet gateway, run ping both from a workstation behind the router and then from the router itself.

On a multihomed host, use ping-I <interface> to specify which interface to use.

Don't block echo-request, echo-reply, time-exceeded, or destination-unreachable ping messages. Some admins block all ping messages at their firewalls, and this is a mistake because many network functions require at least these four ping messages to operate correctly. See Chapter 3 to learn how to correctly configure your iptables firewall.