route Linux / Unix Command

The 'route' command adjusts IP routing tables

Route 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'

Linux route table

For most normal home Linux aficionados, 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 people's home setups, Linux and the router work hand-in-hand to optimize routes.

Examples of 'route'

The following command examples yield specific behavior:

route add -net 127.0.0.0

  • Adds the normal loopback entry, using netmask 255.0.0.0 (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 192.56.76.0 netmask 255.255.255.0 dev eth0

  • Adds a route to the network 192.56.76.x through eth0.
route add default gw mango-gw

  • 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 actually be used for that route depends on how we can reach mango-gw—the static route to mango-gw will have to be set up before.
route add ipx4 sl0

  • Adds the route to the ipx4 host through the SLIP interface (assuming that ipx4 is the SLIP host).
route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4

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

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