route

From RaySoft

Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program.[1]

Documentation

Subcommands & Parameters

-A FAMILY
Use the specified address FAMILY.
-n
Show numerical addresses instead of trying to determine symbolic host names. This is useful if you are trying to determine why the route to your nameserver has vanished.
add
Add a new route.
del
Delete a route.
-host
The target is a host.
-net
The target is a network.
netmask NETMASK
When adding a network route, the NETMASK to be used.
gw GATEWAY
Route packets via a GATEWAY.
dev DEVICE
Force the route to be associated with the specified DEVICE, as the kernel will otherwise try to determine the device on its own. In most normal networks you won't need this.

Examples

Define default gateway
route add 'default' gw '10.0.0.1' dev 'eth0'
Modify routing table
route add -net '172.16.0.0/16' gw '10.0.0.1' dev 'eth0'
route

Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.0.0      10.0.0.1        255.255.0.0     UG    0      0        0 eth0
10.20.0.0       *               255.255.0.0     U     0      0        0 eth0
default         10.0.0.1        0.0.0.0         UG    0      0        0 eth0
route del -net '172.16.0.0/16' gw '10.0.0.1' dev 'eth0'
route

Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.20.0.0       *               255.255.0.0     U     0      0        0 eth0
default         10.0.0.1        0.0.0.0         UG    0      0        0 eth0
Add a static route (CentOS)

The corresponding file is /etc/sysconfig/network-scripts/route-eth0.

172.16.0.0/16 via 10.0.0.1

Restart the network staff

/etc/init.d/network restart

References

  1. man 8 'route'