In certain cases, our pc needs more than one interface and ip address. This post about how to add static IP route on windows. For example, conditions like this:
- The PC has 2 internet interfaces, and wants to determine the outgoing traffic through which interface to a certain destination IP address range.
- The PC has multiple IP addresses and needs to direct traffic to a particular subnet.
How can I communicate with the IP address segment differently from the gateway without passing through the router or gateway?
Here’s the solution.
View Routing Table on Windows
At first, Before you get st arted adding routes you have to open Command Prompt (Admin). The trick is to type “cmd” in the loop icon and if cmd appears click “run as admin”.
At the Command Prompt Admin, type the following command:
destinationSpecifies the host.
MASKSpecifies that the next parameter is the ‘netmask’ value.
netmaskSpecifies a subnet mask value for this route entry. If not specified, it defaults to 255.255.255.255.
interfacethe interface number for the specified route.
METRICspecifies the metric, ie. cost for the destination.
Add a Static Route
To add static route, type this command:
route ADD destination_network MASK subnet_mask gateway_ip metric_cost
route ADD 10.90.10.0 MASK 255.255.255.0 192.168.0.2
In the above command I did not define
metric_cost, the value a
metric_cost is one greater than the 0.0.0.0 destination entry will be used. See picture below.
The way to add a static route like this there are weakness if the PC is restarted. the route will disappear from the routing table.
To make it permanent, add the
-p parameter to the command. Like this.
route -p ADD 10.90.10.0 MASK 255.255.255.0 192.168.0.2
Delete Static Route Windows
To delete static routes you can use the following command:
route delete destination_network
route delete 10.90.10.0
To see result, type
route print and see IPv4 Route Table.
May be it’s helpful, please feel free to leave a comment if you have any questions and I’ll appreciate it.