I’ve been playing with lots of networking scenarios over the last few weeks and I’ve picked up a number of useful techniques and tools for solving certain problems. This post will briefly outline the thinking behind my network troubleshooting, and will include my step-by-step responses to particular problems.
General Strategies: External Network Access
I recently was configuring a server that had three network interface cards (NICs) and three networks to connect to. One of the networks was public, with an internet connection, while the other two were entirely private. If you’re in a similar situation, or your regular external network isn’t working properly, try this:
Step 1 – Confirm your interfaces are correctly configured
The usual FIRST first step is a simple ping test, where we run the command
$ ping google.ca
and if things go well, we see something like this:
$ ping google.ca PING google.ca (74.125.226.87) 56(84) bytes of data. 64 bytes from yyz06s07-in-f23.1e100.net (74.125.226.87): icmp_seq=1 ttl=53 time=2.82 ms 64 bytes from yyz06s07-in-f23.1e100.net (74.125.226.87): icmp_seq=2 ttl=53 time=2.62 ms 64 bytes from yyz06s07-in-f23.1e100.net (74.125.226.87): icmp_seq=3 ttl=53 time=3.06 ms ...
But if you’re reading this, things probably didn’t go well. This is why the first step is to make sure (on Ubuntu anyway) that your interfaces file (/etc/network/interfaces) is correctly configured to connect to your external network.
Two useful tools for this are ip link, which shows the state of all interfaces on the machine, and ip addr, which shows the addresses assigned to the interfaces on the machine.
Step 2 – Confirm your dns settings are correct
You may stumble on this gem:
$ ping google.ca ping: unknown host google.ca
…which usually means a problem with your DNS server (or lack of one). Ensure that your interfaces file includes a line specifying which DNS server you are to be using. Pay attention to line 7:
# Primary interface auto eth0 iface eth0 inet static address 10.0.0.2 netmask 255.255.255.0 gateway 10.0.0.1 dns-nameservers 8.8.8.8
If you had this line there, with a different IP for the DNS server, switch it to the one listed in the example above. 8.8.8.8 is the IP address for Google’s public DNS server and should always work.
Still not working?
Step 3 – Confirm your kernel has a route to the server you are pinging
At this point, the kind of error you’re experiencing probably looks like this:
$ ping google.ca ping: no route to host
Ubuntu Linux comes with a command called route which shows the kernel routing table – a set of basic rules on where to send packets. Running the command will show you something like this:
$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 eth0
Line 6 is my default gateway. We know this because the destination is 0.0.0.0 – which represents any and all IP addresses. So what does this mean? In plain english, the rule above is:
If a TCP/IP packet has a destination that is not otherwise specified on this list, send the packet to 10.0.0.1 and it’ll get there okay.
So what happens if you don’t have a default gateway (that is, a rule with the destination 0.0.0.0)? Or, as was my case, you have more than one?
First, make sure you have an IP address on the public network using ip addr:
$ ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:1c:c0:72:48:b9 brd ff:ff:ff:ff:ff:ff inet 10.0.0.10/24 brd 10.0.0.255 scope global eth0 inet6 fe80::21c:c0ff:fe72:48b9/64 scope link valid_lft forever preferred_lft forever
The highlighted lines are the IPs assigned to the interfaces. Assume that line 9 is a connection on my public network. So far, this means that I am connected to it. Next, add the default gateway manually:
$ route add default gw 10.0.0.1
You can delete gateways using the same syntax, but “del” instead of “add”. Check the man pages for more information.
Conclusion
These tools are your friends:
- ip link
- ip addr
- ifconfig (which I didn’t cover, but shows all active interfaces)
- route
- vi /etc/network/interfaces
- ping
Happy networking!