route Command in Linux
Overview
The route command in Linux is an essential tool for systems administrators. It allows them to display and manipulate IP routing tables. It is used to configure static routes, which are often needed when setting up network configurations. This command is vital for managing the flow of traffic within a network.
Syntax of route Command in Linux
The basic syntax of the route command in Linux is as follows:
Where:
- add|del|change|get: These options specify the action to be performed. They can either add, delete, change routes, or get routing information.
- -net|-host: These options specify whether the target is a host or a network.
- target: This represents the destination.
- netmask: This is used to specify the netmask.
- gw: This stands for 'gateway'. It specifies the gateway.
- [dev] If: This specifies the interface.
Options in route command in Linux
-
-n: Show numerical addresses instead of trying to determine symbolic host names.
For example -
Output:
This command displays the routing table with numerical addresses.
-
add: Used to add a route.
For example -
This command adds a route to the 192.168.2.0 network with the specified netmask and gateway.
-
del: Used to delete a route.
For example -
This command deletes the route to the 192.168.2.0 network with the specified netmask and gateway.
Example Usages
-
Display the IP routing table:
Output:
Explanation: This command displays the current IP routing table.
-
Add a default gateway:
Explanation: This command sets 192.168.1.1 as the default gateway.
Tips
-
The route command is being phased out in favor of the 'ip route' command. However, it is still widely used and found in many systems.
-
Always double-check your routing table after making changes to verify that routes have been added or removed correctly.
Advanced Use Cases of route Command in Linux
-
Change an existing route:
Explanation: This command changes the gateway for the 192.168.2.0 network to 192.168.1.2.
-
Get the route to a specific host or network:
Output:
Explanation: This command retrieves the routing details for the specified IP address.
-
Delete all routes:
Explanation: This command deletes all the routes in the routing table. This command should be used with caution as it can disrupt network connectivity.
Conclusion
-
The route command in Linux is a powerful tool for managing IP routing tables.
-
It provides several options to add, delete, change and get routing information.
-
While the 'ip route' command is gradually replacing it, the route command is still widely used and crucial for Linux system administrators.