route Linux Commands
What is Linux route Command?
Explanation
route COMMAND:route command displays routing table resides in kernel and also used to modify the routing table.The tables which specifies how packets are routed to a host is called routing table.
SYNTAX :
route [options]
OPTIONS:
-n |
dispalys routing table in numerical[IP Address] format |
-e |
dispalys routing table in Hostname format |
add |
Adds a new route to the routing table |
del |
Deletes a route from the routing table |
Options used with add and del :
-net |
Indicate the target is network |
-host |
Indicate the target is host |
gw |
Specifies the gateway of target host/network |
netmask |
Used to specifiy the subnet-mask of destination network/host |
dev |
Specify the device or interface where the packets will be sent |
reject |
rejects the packets sent to particular route/host |
EXAMPLE:
- To dispaly the routing table:
route -n
The above command will print:
Destination | Gateway | Genmask | Flags | Metric | Ref | Use | Iface |
192.168.0.0 | 0.0.0.0 | 255.255.255.0 | U | 0 | 0 | 0 | eth0 |
169.254.0.0 | 0.0.0.0 | 255.255.0.0 | U | 0 | 0 | 0 | eth0 |
0.0.0.0 | 192.168.0.1 | 0.0.0.0 | UG | 0 | 0 | 0 | eth0 |
In above table: |
Destination | -Indicates the IP address of desination host/network |
Gateway | -Indicates gateway from which desination host/network could be reached |
Genmask | -Indicates the subnetmask destination |
Flags | -Indicates the current status of route
- U - Route is up
- H - Target is a host
- G - Use gateway
|
Iface | -Indicates the interface |
- To add static route to a network in the routing table:
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0
In above command: |
add | -Indicates that the route is added to routing table. |
-net | -Indicates that desination is a network. |
192.168.0.1 | -Indicates IP address of destination network. |
netmask | -Indicates the subnetmask of destination network. |
gw 192.168.1.1 | -Indicates the gateway of destination network. |
dev eth0 | -Indicates that the packets are routed via the interface eth0. |
- To delete a route from the routing table:
route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0
The above command will delete the route to 192.168.1.0 from the routing table.