The route command
The route command displays or modifies the computer's routing table. To display the routing table, use route without any parameters. To add an entry to the routing table, use this syntax:
route add [ -net | -host ] address [options]
To delete an entry, use this syntax:
route del [ -net | -host ] address [options]
The available options are as follows:
- netmask mask: Specifies the subnet mask for this entry.
- gw address: Specifies the Gateway Address for this entry.
- dev if: Specifies an interface (such as eth0 or eth1) for this entry.
If you enter route by itself, with no parameters, you'll see the routing table, as in this example:
$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 * 255.255.255.0 U 0 0 0 eth1 192.168.1.0 * 255.255.255.0 U 0 0 0 eth1 169.254.0.0 * 255.255.0.0 U 0 0 0 eth1 127.0.0.0 * 255.0.0.0 U 0 0 0 lo default 192.168.1.1 0.0.0.0 UG 0 0 0 eth1
Suppose that your network has a second router that serves as a link to another private subnet, 192.168.2.0 (subnet mask 255.255.255.0). The interface on the local side of this router is at 192.168.1.200. To add a static route entry that sends packets intended for the 192.168.2.0 subnet to this router, use a command like this:
$ route add 192.168.2.0 netmask 255.255.255.0 gw
192.168.1.200
In this tutorial:
- Linux Commands
- Command Shell Basics
- Editing commands
- Wildcards
- Redirection and piping
- Environment variables
- Shell scripts
- Directory and File Handling Commands
- The cd command
- The mkdir command
- The rmdir command
- The ls command
- The cp command
- The rm command
- The mv command
- The touch command
- The cat command
- Commands for Working with Packages and Services
- The rpm command
- Commands for Administering Users
- The usermod command
- The chage command
- The passwd command
- The newusers command
- The groupadd command
- The groupdel command
- Commands for Managing Ownership and Permissions
- The chgrp command
- The chmod command
- Networking Commands
- The ipconfig command
- The netstat command
- The ping command
- The route command
- The traceroute command