Learn how to use the route command to display network information on Linux.
Route is used when you want to work with the IP/kernel routing table. It is typically used to setup static routes to specific networks of hosts via an interface. It is used for updating or showing the IP/kernel routing table.
You can use Kali Linux in a VM for this lab.
Some route command features may require high privileges to work. First of all, we have to be the “root” user using the terminal:
sudo su –
In order to use route, you may need to install it. It comes in a package called net tools, and it can be installed on Kali Linux with the following command:
Sudo apt-get install net-tools
Once this is installed, we will first view the help screen using the following command:
We will then use a simple command to view our IP/kernel routing table:
If we want to display the previous routing table in ful numeric form, we can use this command:
This is useful for more accurately determining values in the routing table.
We can add a default gateway by executing the following command:
route add default gw xxx.xxx.xxx.xxx
Replace the x’s with the your gateway IP. This assigns a gateway address through which all packets that do not belong to the network are forwarded.
To view the kernel’s routing cache information, we can use the following command:
The cache is used to route the packets faster. This command will print all saved cache information.
We can specify to reject routing to a specific host or network using this command:
route add -host 192.168.1.51 reject
If we attempt to ping the above IP address, we will be presented with a “Network is unreachable” notice.
If we want to get the details of the kernel/IP routing table, we can use the following ip command:
This will detail the kernel/IP routing table.
In some instances, we may wish to delete the default gateway, which we can achieve by running this command:
route del default
NOTE: this may lead to some malfunctioning of your internet connection and it is important you take note of your default gateway before executing this command.
To get the output in relation to IPv4 and IPv6, we can use the following commands respectively:
ip -4 route
The above will display the entries with IPv4 only
ip -6 route
The above will display the entries with IPv6 only