When packets don't reach their destination (ping or traceroute fail), the first thing an experienced user checks is the cables. The next thing to check is the routing tables. If a system lacks a default gateway (0.0.0.0), it will only find machines on its physical network. If you have multiple networks running on the same wires, you'll need to add routes to allow machines attached to one network to send packets to another.
The ip route command reports known routes:
$ ip route 10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1 192.168.87.0/24 dev vmnet1 proto kernel scope link src 192.168.87.1 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.44 default via 192.168.1.1 dev eth0 proto static
The ip route report is space-delimited. After the first element, it consists of a set of keys and values.
The first line in the preceding code describes the 10.8.0.2 address as a tunnel device that uses a kernel protocol, and this address is only valid on this tunnel device. The second line describes the 192.168.87.x network used to communicate with virtual machines. The third line is the primary network of this system, which is connected to /dev/eth0. The last line defines the default route, which routes to 192.168.1.1 through eth0.
The keys reported by ip route include the following:
- via: This refers to the address of the next hop.
- proto: This is the protocol identifier of the route. The kernel protocol is a route installed by the kernel, while static routes are defined by an administrator.
- scope: This refers to the scope where the address is valid. A link scope is only valid on this device.
- dev: This is the device associated with the address.