Static Routing - Linux

OS: 
SummaryStatic Routing uses static routing tables to route traffic.  Routing tables are manually configured.
Static Routing ConfigurationsSetting static routing table entries for a Linux PC
route add -net netaddress netmask mask gw gw_address
route add -net netaddress netmask mask dev iface
Adds a routing table entry for the network prefix identified by IP address netaddressand netmask mask. The next-hop is identified by IP address gw_address or by interface iface.
route add -host hostaddress gw gw_address
route add -host hostaddress dev iface
Adds a host route entry for IP address hostaddress with the next-hop identified by IP address gw_address or by interface iface.
route add default gw gw_address
Sets the default route to IP address gw_address
route del -net netaddress netmask mask gw gw_address
route del -host hostaddress gw gw_address
route del default gw gw_address
Deletes an existing route from the routing table. It isn’t necessary to type all arguments. If enough arguments are provided that it can be matched with an existing routing entry, the first entry that matches the given arguments is deleted.
route -e
Displays the current routing table with extended fields. The command is identical to the netstat -r command.
route -c

Displays the routing table cache.

 

 Making changes to the routing tables
PC1% route add -net 10.21.0.0 netmask 255.255.0.0 gw 10.11.1.4 -The command for adding a route for the network prefix 10.21.1.0.0/16 with next hop address 10.11.1.4
PC1% route add -host 10.0.2.31
gw 10.0.1.21
-The command to add a host route to IP address 10.0.2.31 with the next-hop set to 10.0.1.21
PC1% route add default gw 10.0.4.4 -The command to add the IP address 10.0.4.4 as the default gateway is done with the command
PC1% route del -net 10.21.0.0 netmask 255.255.0.0

PC1% route del -host 10.0.2.31

PC1% route del default
-The commands to delete the entries created with previous commands