How to add/remove/change route

The route command is used to show/manipulate the IP routing table. It is primarily used to setup static routes to specific host or networks via an interface.

Display existing routes

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.2.8.1        0.0.0.0         UG    0      0        0 eth0
10.2.8.0        *               255.255.252.0   U     0      0        0 eth0
10.10.16.0      10.10.32.53     255.255.240.0   UG    0      0        0 tun0

Change default gateway

# route del default
route add default gw 10.2.0.4

Add a route for a given network

route add -net 172.17.255.0/24 gw 195.54.62.1

Remove a route for a given network

route del -net 172.17.255.0/24 gw 195.54.62.1

Reject routing for a given network

route add -net 192.168.1.0/24 reject