Networking / Beginners

The route command

The route command displays or modifies the computer's routing table. To display the routing table, use route without any parameters. To add an entry to the routing table, use this syntax:

route add [ -net | -host ] address [options]

To delete an entry, use this syntax:

route del [ -net | -host ] address [options]

The available options are as follows:

  • netmask mask: Specifies the subnet mask for this entry.
  • gw address: Specifies the Gateway Address for this entry.
  • dev if: Specifies an interface (such as eth0 or eth1) for this entry.

If you enter route by itself, with no parameters, you'll see the routing table, as in this example:

$ route
Kernel IP routing table
Destination Gateway 	Genmask 	Flags Metric Ref Use Iface
192.168.1.0 * 		255.255.255.0 	U 	0    0 	  0  eth1
192.168.1.0 * 		255.255.255.0 	U 	0    0 	  0  eth1
169.254.0.0 * 		255.255.0.0 	U 	0    0 	  0  eth1
127.0.0.0   * 		255.0.0.0 	U 	0    0 	  0  lo
default     192.168.1.1 0.0.0.0 	UG 	0    0 	  0  eth1

Suppose that your network has a second router that serves as a link to another private subnet, 192.168.2.0 (subnet mask 255.255.255.0). The interface on the local side of this router is at 192.168.1.200. To add a static route entry that sends packets intended for the 192.168.2.0 subnet to this router, use a command like this:

$ route add 192.168.2.0 netmask 255.255.255.0 gw
192.168.1.200
[Previous] [Contents] [Next]