Routing Table: Do or Die for the packet
After a short hiatus we are back and today the post is about Routing in Linux. The destiny of your packet is dependent on the the Routing table. Will the packet be forwarded out or will it be dropped, all (well not all) depends on the routing table. In this post we will see the command and some of it's flags that help us see/edit our routing table. netstat is the command that will give us all that we want and even more (much more). Some of the interesting flags are:--r Routing --a All interfaces --n do not resolve
$ netstat -ra Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default 192.168.0.1 0.0.0.0 UG 0 0 0 wlan0 192.168.0.0 * 255.255.255.0 U 0 0 0 wlan0
In the above output we will describe all columns from left to right:Destination Network --> Where the packet wants to go Gateway --> Where the packet will go to go to destination networkGenMask --> Subnet mask to define the destination network Flags: This characterize the route: U means active (UP), G means Gateway, and H is a Host Route iface --> interface that will be used to reach to the gateway
$ netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 wlan0 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0 -n forces no name resolution and hence we see 0.0.0.0 instead of default. The different ways in which we can add routes to our device are static or dynamic. For dynamic routing entries we will have to run routing protocols like OSPF/BGP with router. Following are the static ways of doing adding a route:
route add -net $Network netmask $SubnetMask gw $Gateway $introute add default gw $Gateway $int
This was a brief overview of how to see and edit routing table in Linux. Hope this was helpful. Keep Blogging!













