From this guide, you will learn in a couple of minutes what the ROUTE command is, how to view the routing table and how to add a static route in Windows 7/8/10/11 using the route command on the command line.
What is a routing table?
In computers, routing is the process of transmitting IP traffic to destinations on a network through intermediate router nodes. Every operating system, including Windows, has a routing table, a tool that contains information about how to connect to networks of all types. These tables use a dynamic routing technique in which a router is able to choose the best location to forward packets based on information it receives from other router nodes. You can always view your routing table using commands in the command line. You must run the command prompt with Administrator rights.
- To do this, click the Start button and select the menu item Programs > Accessories > Command Prompt, or press the key combination Win + R and enter the following command: cmd.
- At the command prompt, enter the following command: route print
- Confirm pressing Enter.
You will see a list of network destinations and gateways to which data from your computer is dynamically sent.
But you can manually control the routing of traffic yourself by setting your table to a static route, which will not change after that. This way your system will only send traffic to a specific gateway. Why do this? This can be useful in cases where it is important to you to diversify the different traffic going to different IP address ranges. Read on to find out how.
How to Add a Static TCP/IP Route to the Windows Routing Table?
To add a static route to the routing table, you will need to use the Route command, but in this case additional parameters are added to it:
ROUTE [-f] [-p] [-4|-6] command [destination] [MASK netmask] [gateway] [METRIC metric] [IF interface]
-f - Clears route tables of all gateway entries. When one of the commands is specified, the tables are cleared before the command is executed.
-p - When used with the ADD command, sets the route to be saved when the system is rebooted. By default, routes are not saved across reboots. Ignored for other commands that change the corresponding permanent routes. This option is not supported on Windows 95.
-4 — Mandatory use of the IPv4 protocol.
-6 — Mandatory use of the IPv6 protocol.<command> can be one of the following commands:
ADD - Add a route
PRINT - Print route
DELETE - Delete a route
CHANGE - Change an existing route
destination — The node to be addressed.
MASK — Indicates that the following parameter is interpreted as a netmask.
netmask — The subnet mask value for this route entry. If this parameter is not specified, the default value is 255.255.255.255.
interface — The interface number for the specified route.
METRIC - Definition of metric, i.e. prices for the addressed node. The lower the metric value, the higher the priority of the node when constructing a route.
As an example, let's take three main subnets used as local:
You should type the following three lines:
route -p add 192.168.0.0 mask 255.255.0.0 <your_gateway>
route -p add 10.0.0.0 mask 255.0.0.0 <your_gateway>
route -p add 172.16.0.0 mask 255.240.0.0 <your_gateway>
For example, your gateway is 192.168.50.1, then the commands will look like this:
route -p add 192.168.0.0 mask 255.255.0.0 192.168.50.1
route -p add 10.0.0.0 mask 255.0.0.0 192.168.50.1
route -p add 172.16.0.0 mask 255.240.0.0 192.168.50.1
If you need to remove static routes, simply enter the following commands:
route delete 192.168.0.0
route delete 10.0.0.0
route delete 172.16.0.0