Skip to content

Linux route command

The Linux route command is used to view and manipulate the IP routing table. It allows you to display the current routing table, add new routes, delete existing routes, and make changes to the routing table. The syntax for the route command includes specifying the target network, gateway, netmask, and interface. By using different options, you can customize the behavior of the command. Understanding how to use the route command is essential for network administrators and anyone working with network configurations in a Linux environment.

route Syntax:

Terminal window
route [options] [add|del|flush] [destination] [gateway]

Options:

OptionDescription
-nShow numerical addresses
-vVerbose output
-eDisplay other/more details
-A familySpecify the address family

Parameters:

ParameterDescription
addAdd a new route
delDelete a route
flushRemove all entries from the routing table
destinationNetwork destination for the route
gatewayGateway for the route

route Usage:

Display the routing table

Terminal window
route

Displays the current routing table on the system.

Add a new route

Terminal window
sudo route add -net 192.168.10.0 netmask 255.255.255.0 gw 192.168.1.1

Adds a new route for the network 192.168.10.0 with the specified netmask and gateway.

Delete a specific route

Terminal window
sudo route del -net 10.0.0.0 netmask 255.0.0.0

Deletes the route for the network 10.0.0.0 with the specified netmask.

Set the default gateway

Terminal window
sudo route add default gw 192.168.1.1

Sets the default gateway to 192.168.1.1 for outgoing traffic.

How do I use route in Linux?

To use the route command in Linux, execute the following command:

Terminal window
route

How can I display the routing table in Linux?

To display the routing table in Linux, use the following command:

Terminal window
route -n

How do I add a static route in Linux?

To add a static route in Linux, use the following command:

Terminal window
sudo route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.1

How do I delete a specific route in Linux?

To delete a specific route in Linux, use the following command:

Terminal window
sudo route del -net 192.168.1.0 netmask 255.255.255.0

How can I change the default gateway in Linux using the route command?

To change the default gateway in Linux using the route command, use the following command:

Terminal window
sudo route add default gw 192.168.1.1

How do I show kernel routing information in Linux?

To show kernel routing information in Linux, use the following command:

Terminal window
route -e

How can I see the IP addresses for local and foreign connections in Linux using the route command?

To see the IP addresses for local and foreign connections in Linux using the route command, use the following command:

Terminal window
route -n

Applications of the route command

  1. Display the routing table:
  2. Add a new route to the routing table:
  3. Delete a route from the routing table:
  4. Change attributes of an existing route:
  5. Show the IP routing table statistics:
  6. Flush all routes from the routing table:
  7. Display the kernel IP routing table with more information:
  8. Print the route for the target host or network:
  9. Show the routing cache:
  10. Display multicast routing information: