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.
Installing route Command
Many Linux distributions do not have route command pre-installed. To install it use the following commands as per your Linux distribution.
In case of Debian/Ubuntu
$sudo apt-get install net-tools
In case of CentOS/RedHat
$sudo yum install net-tools
In case of Fedora OS
$sudo dnf install net-tools
Working with route command
1. To display the IP/kernel routing table.
$route

It displays the routing table entries.
2. To display routing table in full numeric form.
$route -n

It is even useful when you have to determine why the route to nameserver has even vanished.
3. To add a default gateway.
$sudo route add default gw 169.254.0.0

This assigns a gateway address on which all the packets that do not belong to the network are forwarded.
Note: In this case the, We wish to choose 169.254.0.0 as the default gateway. You may choose as per your need.
4. To list kernel’s routing cache information.
$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.
5. To reject routing to a particular host or network.
$sudo route add -host 192.168.1.51 reject

Now if you will ping to the above-mentioned IP it will display “Network is unreachable”.
6. To get details of the kernel/IP routing table using ip command.
$ip route

This will give the details of the kernel/IP routing table and in this case, we have used IP command.
7. To delete the default gateway.
$route del default

Caution: This may lead to some malfunctioning of internet. Keep a note of your default gateway before proceeding with the command.
This will remove the default gateway.
8. To get the details of the local table with destination addresses assigned to the localhost.
$ip route show table local

This will print the details of the local table.
9. To get output related to IPv4.
$ip -4 route

This will only display the entries with ipv4.
10. To get output related to IPv6.
$ip -6 route

This will only display the entries with ipv6.
Recommended Posts:
- let command in Linux with Examples
- cmp Command in Linux with examples
- cut command in Linux with examples
- cpp command in Linux with Examples
- mv command in Linux with examples
- tty command in Linux with examples
- cp command in Linux with examples
- rcp Command in Linux with examples
- ip command in Linux with examples
- help Command in Linux with examples
- last command in Linux with Examples
- apt command in linux with examples
- tee command in Linux with examples
- df Command in Linux with examples
- col command in Linux with Examples
- Cat command in Linux with examples
- gdb command in Linux with examples
- ZIP command in Linux with examples
- ssh command in Linux with Examples
- apm Command in Linux With Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

