A routing table is a set of rules, usually viewed in table format, that is used to track where data packets traveling over an Internet Protocol (IP) network will be directed. It dictates where all packets go when they leave a system. Most routers, and this includes the one built into your Windows PC, use …
A routing table is a set of rules, usually viewed in table format, that is used to track where data packets traveling over an Internet Protocol (IP) network will be directed. It dictates where all packets go when they leave a system. Most routers, and this includes the one built into your Windows PC, use some form of dynamic routing, meaning that the router is capable of selecting the best place to forward packets based on information it gets from other routers. You can see it if you use the “traceroute” command to watch the connections a packet can make as it reaches its final destination.
Most routers will allow you to add a static route–one that does not get dynamically updated–if you want to always forward certain traffic to a specific router or gateway. Generally, there is no need for this, but there are a few exceptions, for example:
You have two internet connections–perhaps one is for work–and you want all traffic to a certain IP address range to go out over one of those connections.
You have set up multiple subnets on your network and need to direct traffic to a particular subnet.
You want better, more specific control over your Windows PC, which you used as a router.
You will need to dive into the Command prompt to add a static route to the Windows routing table, but it is not too difficult if you follow these steps.
It will be helpful to view the routing table first, so hit Command + X and select “Command Prompt (Admin)” on the Power Users menu.
At the Command prompt, type route print and hit Enter.
You should see a long list of network destinations and the gateways to which packets are forwarded when they are headed to that destination. Unless you’ve already added static routes to the table, everything you see here will be dynamically generated.
To add a static route to the table, type a command using the following syntax:
route add destination_network MASK subnet_mask gateway_ip metric_cost
The subnet_mask and metric_cost part of the commands are optional. Note that if you do not specify a subnet mask, 255.255.255.0 will be used automatically. Likewise, if you do not specify a metric cost, a cost one greater than the 0.0.0.0 destination entry will be used. The metric cost value is just a cost that is relative to other costs in the table and is used when Windows decides between multiple routes that could reach the same destination.
If you wanted to add a route specifying that all traffic bound for the 192.192.168.35.0 subnet went to a gateway at 192.168.0.2 and you just wanted to use the automatic metric cost, you would use the following command:
route add 192.168.35.0 MASK 255.255.255.0 192.168.0.2
Now, if you were to use the “route print” command to look at the table, you should be able to find your new static route.
It is important to keep in mind that when you add a static route, it only lasts until the next time you start Windows, by default. This helps keep the table uncluttered.
Writing batch scripts is an option to counter the short window of time issue, and it is not too hard. But if you’re just adding one or two static routes that you don’t expect to change often, you can just add the -p option to the command to make the route persistent. A persistent route, as its name suggests, stays in place even when Windows starts up. Your command should look something like this:
route -p add 192.168.35.0 MASK 255.255.255.0 192.168.0.2
To undo whatever you did above, the command mostly stays the same, except that this time, you want to delete it. Type a command using the following syntax:
route delete destination_network
Given our earlier example, if you want to delete that specific static route with that destination network, you just have to type this command in:
route delete 192.168.35.0
Overall, it is an easy process to add and remove static routes to the Windows routing table. Considering the few circumstances in which you might need to use this set of instructions, it is always an option to keep open.