Output of route n with NoDefault Route

bible:~ # route -n Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

As you can see, this example uses the -n option to suppress the use of name resolution. When you suppress name resolution, it speeds up the execution of the command because it will not try to resolve an IP address to a name using your name resolver, which could at best be your local host's file or at worst be your network's DNS server.

You have two routes that have automatically been assigned by the kernel when the two devices, eth0 and lo, were created. If you need to talk to a machine in the 192.168.0.0/24 network, that traffic is routed to the eth0 device. The same is true for the 127.0.0.0/8 network, which is routed over the lo (loopback) adaptor.

However, if you want to communicate with a machine on any other network, say 10.0.0.0/24, you get an error that the machine cannot be found because you are currently unable to route packets outside of your network.

To combat this, you need to set up a default route for all traffic you do not know about. To do this, you create a default route with the following command:

bible:~ # route add default gw 192.168.0.254

Here you have used the route command to add a new route to the routing table. Table 15-2 explains the options used in the preceding command example.

The route Command-Line Options

Options

Description

Add

Adds a route to the routing table

gw

Specifies that packets should be sent to this gateway

192.168.0.254 The IP address of the gateway/default router

192.168.0.254 The IP address of the gateway/default router i- : i j The route command can also be used to add static routes for other networks f-c '3 ^ ^à^'-vï-j (for example, if you know that a specific router attached to ethl is servicing a destination network you want to reach without using your default route). For example, if you want to add a specific route for the 192.168.1.0 network, you can use route add -net 192.168.1.0/24 192.168.0.254. This routes traffic for 192.168.1.0/24 through the 192.168.0.254 router.

When the default route has been added, you can take another look at the routing table (see Listing 15-3).

Was this article helpful?

0 0

Post a comment