route Linux / Unix Command

The 'route' command adjusts IP routing tables

The route command manipulates the Linux kernel's IP routing tables. It sets up static routes to specific hosts or networks through an interface after it has been configured with the ifconfig program.

Use Cases for 'route'

For most home Linux users, there's not much use for the route command. The command overrides the operating system's routing tables that translate Internet Protocol addresses into specific routings through the local network. On most home setups, Linux and the router work hand-in-hand to optimize routes.

Linux route table

Examples of 'route'

The following command examples yield specific behavior.

To add the normal loopback entry, using netmask (class A net, determined from the destination address) and associated with the lo device (assuming this device was previously set up correctly with ifconfig):

route add -net

To add a route to the network 192.56.76.x through eth0:

route add -net netmask dev eth0

The following command adds a default route (which will be used if no other route matches). All packets using this route will be gatewayed through mango-gw. The device, which will be used for that route, depends on how it can reach mango-gw—the static route to mango-gw will have to be set up before.

route add default gw mango-gw

To add the route to the ipx4 host through the SLIP interface (assuming that ipx4 is the SLIP host):

route add ipx4 sl0

This command adds the net 192.57.66.x to be gatewayed through the former route to the SLIP interface:

route add -net netmask gw ipx4

Use the man command (% man) to see how a command is used on your computer.