Route Command in Linux with examples

Route command in Linux is used when you want to work with the IP/kernel routing table. It is mainly used to set up static routes to specific hosts or networks via an interface. It is used for showing or update the IP/kernel routing table. Route command can be used to show and modify the network routing table in a Linux system. Therefore, In order to make your computers communicate with other devices on the network, you have to define the route for them.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System commands queries.

In this context, we shall look into how to use the route command in Linux.

How to Install route Command in your Linux system ?

Many Linux distributions do not have route command pre-installed. To install it use the following commands as per your Linux distribution.

1. In case of Debian/Ubuntu:

$ sudo apt-get install net-tools

2. In case of CentOS/RedHat:

$ sudo yum install net-tools

3. In case of Fedora OS:

$ sudo dnf install net-tools

How to use route command ?

1. To display the IP/kernel routing table, run the command:


This command displays the routing table entries.

2. To display routing table (the current routing table) in full numeric form, run the command:

$route -n

Another way to describe more detail about which network interface of routes is running the command:

$ ip route show

3. To add a new route

If your computer has more than one network interface and you want to add a new route, the computer will send traffic through that new gateway. You can use the route add command as below:


For example:

$ sudo route add -net gw eth2

To add a new route to a host, run the following command:

$ sudo route add -host <HOST-IP> gw <GATEWAY>

For example:

$ sudo route add -host gw

In the Flags column, there are some values that are difficult to understand. The following section is a quick explanation:

  • U: up
  • H: host
  • G: gateway
  • !: rejected route

4. How to Delete a route ?

If you no longer use a specific route and you want to delete it, you can simply run the following command:


For example:

$ sudo route del -net gw eth2

To reject a route but you want to keep it on the routing table, run the command with the reject option:

$ sudo route add -host reject

5. To list kernel's routing cache information, execute the command:

$ route -Cn

To route the packets faster, Kernel maintains this routing cache information. The above command will print the cache information. In this case, the cache information is maintained.

[Need help in fixing Linux System errors? We can help you. ]


This article covers how to use the route command in a Linux system with examples. Linux provides the ip route command in order to manage the routing table. The routing table is used to set routes for different destination IP addresses. Even there is a default route in most of the cases which are used to sent IP packets to the other networks we may need to add new routes via the command-line interface by using the ip route add command.

Important Linux commands:

  • arp — Manipulate the system ARP cache.
  • ifconfig — View or modify the configuration of network interfaces.
  • ip — Display and manipulate information about routing, devices, policy routing and tunnels.
  • netstat — Print information about network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.