It is possible to configure a Linux system to act as a router. The role of a router is to pass traffic from one network segment to another, based on the network ID of packets. In order to properly direct traffic to the appropriate subnet (and prevent traffic from getting to certain subnets, too), routing table entries are configured. This is not a common configuration for Linux hosts but is important to be aware of.

The route command is used to view the routing table. The command is also used to manipulate the routing table, enabling the administrator to configure desired routes.

Examples include the following.

Command Used To
route View the current routing table on the system.
route add default gw {IP address} Configure a default gateway by its IP address. Packets will be passed to this destination if there are no other routes that match their network ID.
route add –host {IP address} reject Filter traffic destined to the specified address, which enables an administrator to control connections to a particular host. Can also be configured for an entire subnet.


The syntax of the route command is:

Displaying the routing table:

route command examples in Linux

route Command Exaxmples

1. To see the current routing table:

2. To show numerical addresses instead of trying to determine symbolic host names:

3. To use netstat-format for displaying the routing table:

4. To see the kernel routing cache:

5. To add the route into the system:

# route add -net netmask gw
# route add -host netmask gw
# route add -host netmask gw dev eth0 

6. To add a default route via specified gateway:

# route add default ge 

7. To delete a route from the system:

# route del -net netmask gw
# route del -host netmask gw 

8. To reject a route:

# route add -host netmask gw reject
# route add -net netmask gw reject
# route add -net netmask reject 

9. To see the help:

# route -h
# route --help

10. To see the version:

# route -V
# route --version 

11. To set to verbose mode: