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:


  1. To dispaly the routing table:
    route -n

    The above command will print:

    DestinationGatewayGenmaskFlagsMetricRefUseIface
    192.168.0.00.0.0.0255.255.255.0 U 000eth0
    169.254.0.00.0.0.0255.255.0.0 U 000eth0
    0.0.0.0192.168.0.10.0.0.0UG000eth0

    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
  2. 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.
  3. 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.

Ask Questions

Ask Question