route
route
The route
command in Linux is used to view and manipulate the IP routing table. This command displays the current routing table and allows you to add or remove routes. However, like ifconfig
, the route
command is considered deprecated in favor of the ip
command from the iproute2
package.
View the Routing Table:
or
The
-n
option prevents the command from attempting to resolve IP addresses to hostnames, making the output quicker to generate and easier to read.Add a Default Gateway:
This command sets the default gateway to
192.168.1.1
.Add a Route to a Specific Network:
This command adds a route to the network
192.168.2.0
with a netmask of255.255.255.0
, routing through the gateway192.168.1.1
.Add a Host Route:
This command adds a route for a specific host
192.168.1.2
through the gateway192.168.1.1
.Delete a Route:
This command removes the route to the network
192.168.2.0
.
Example of route
Command Output
route
Command OutputWhen you run route -n
, you might see output similar to this:
Using ip
Command for Routing
ip
Command for RoutingThe ip
command provides more functionality and is the modern replacement for route
. Here are equivalent commands using ip
:
View the Routing Table:
Add a Default Gateway:
Add a Route to a Specific Network:
Add a Host Route:
Delete a Route:
Conclusion
While the route
command is still available and useful for simple routing table manipulations, it is recommended to use the ip
command for more advanced and modern network configuration tasks. The ip
command offers a unified and consistent interface for managing both IP addresses and routes, making it a more powerful and flexible tool for network administrators.
help
breakdown
Last updated