In computer networking terms, routing is the process of forwarding TCP/IP packets between hosts that are connected to multiple IP networks. A host computer decides the best route for a packet with the help of a routing table. Routing table contains a default set of routes that are created when TCP/IP is started on a computer and based on that computers TCP/IP configuration.
The routes can be any of the following three type
- Network Route: A route to a specific destination network
- Host Route: A route to a specific host in the network
- Default route: A route that is used when no other route matches the destination address
The routing table of a host running Windows 7 contains the following fields
- Network Destination
- Netmask
- Gateway
- Interface
- Metric
Depending on the type of route, the network destination can be a network address with host bits set to 0 (Network route), a host IP address (Host Route) or 0.0.0.0 (Default route).
Netmask is the subnet mask used with Network destination to match the destination address.
Gateway is the IP address of the node used to forward the packet to other IP networks.
Interface is the address of the local network interface used to forward the IP packets.
Metric is an integer value between 1 to 9999 that indicates the cost for the route. When there are multiple routes for a destination, the route with the lowest metric is chosen.
When a computer needs to forward a packet it checks the routing table for an entry that matches the packets destination address and use the corresponding route. If a match for the destination address is not found then the default route is used which normally forwards the packet to default gateway of the local subnet.
On a Windows system you can use the route
command to view and manipulate routing table. When used without parameters the route
command displays the help. To dispaly all the contents of a routing table, open command prompt and type the command
C:\> route print =========================================================================== Interface List 15...00 ff 10 83 ed 09 ......Juniper Network Connect Virtual Adapter 19...10 0b a9 d1 e4 34 ......Intel(R) Centrino(R) Advanced-N 6205 #5 13...b4 12 4c 13 2c de ......Intel(R) 82579LM Gigabit Network Connection 11...10 2d f4 54 e0 5f ......Bluetooth Device (Personal Area Network) 1...........................Software Loopback Interface 1 21...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter 22...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2 23...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #3 25...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #4 24...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface =========================================================================== IPv4 Route Table =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 192.168.1.254 192.168.1.13 25 10.0.0.0 255.0.0.0 On-link 172.18.135.21 1 10.255.255.255 255.255.255.255 On-link 172.18.135.21 257 127.0.0.0 255.0.0.0 On-link 127.0.0.1 306 127.0.0.1 255.255.255.255 On-link 127.0.0.1 306 127.255.255.255 255.255.255.255 On-link 127.0.0.1 306 224.0.0.0 240.0.0.0 On-link 127.0.0.1 306 224.0.0.0 240.0.0.0 On-link 192.168.1.13 281 255.255.255.255 255.255.255.255 On-link 127.0.0.1 306 255.255.255.255 255.255.255.255 On-link 172.18.135.21 257 255.255.255.255 255.255.255.255 On-link 192.168.1.13 281 =========================================================================== Persistent Routes: None
Adding routes for network traffic segregation
In scenarios where you have multiple network interfaces connected to different networks, adding routes to the host's routing table is necessary to forward the packets to the correct network. To add a static route to the routing table run the route
command as below:
route add destination mask subnetmask gateway if interface
Where destination is the IP address of host or network, subnetmask is the mask for the route entry and interface is the interface number of the interface to be used for that route. For example to add a static route to 172.21.32.0 network with subnet mask 255.255.255.0 and gateway address 192.168.1.13, type the command
route add 172.21.32.0 mask 255.255.255.0 192.168.1.1 IF 19 OK!
To make a static route permanent you can use the -p option when adding the route.
To delete a route, run the route delete
command as below
route delete destination
For example, to delete the route that you added above
route delete 172.21.32.0