route – Display and Set Static Routing Table in Linux

The route command in Linux is used to display and manipulate the kernel’s IP routing table. It is used to define the network interfaces that are used to communicate with other systems on the network. With the route command, you can add, delete, or modify entries in the routing table, and also display the routing table’s contents.

Overview

The basic syntax of the route command is as follows:

route [OPTIONS] [COMMAND] [ADDRESS]

The OPTIONS parameter is optional and can be used to modify the behavior of the command. The COMMAND parameter specifies the action to be performed on the routing table. The ADDRESS parameter is also optional and specifies the network address or host to be affected by the command.

Examples

Here are some examples of how to use the route command:

  1. Display the routing table:
route

This command will display the entire routing table.

  1. Add a new route:
route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.1.1

This command will add a new route to the network 10.0.0.0 with a netmask of 255.0.0.0, and set the gateway to 192.168.1.1.

  1. Delete a route:
route del -net 10.0.0.0 netmask 255.0.0.0

This command will delete the route to the network 10.0.0.0 with a netmask of 255.0.0.0.

  1. Change the default gateway:
route add default gw 192.168.1.1

This command will change the default gateway to 192.168.1.1.

Options

Here are the available options for the route command:

Option Description
-A Specifies the address family to use (inet or inet6)
-C Prints the routing cache
-e Displays the netstat information in extended format
-h Displays the help message
-n Displays the routing table in numeric format
-v Displays the version information
-F Clears the routing table
-I Specifies the interface to use
-N Specifies the routing namespace to use
-T Specifies the route table to use

Troubleshooting tips

Here are some tips for troubleshooting common issues with the route command:

  • If you encounter an error message that says “SIOCADDRT: Network is unreachable”, it means that the network you are trying to add a route to is not reachable. Check your network configuration and make sure that the network is reachable.
  • If you encounter an error message that says “SIOCADDRT: No such process”, it means that the interface you are trying to add a route to does not exist. Check your network configuration and make sure that the interface exists.
  • If you encounter an error message that says “SIOCADDRT: File exists”, it means that the route you are trying to add already exists in the routing table. Use the route change command to modify the existing route.

Notes

  • The route command is used to manipulate the kernel’s IP routing table, which is used to determine the path that network packets take from one host to another.
  • The routing table is organized by destination network, netmask, gateway, and interface. Each entry in the routing table specifies a path to a specific network or host.
  • The route command can be used to add, delete, or modify entries in the routing table, and also to display the routing table’s contents.