what command is used to add static routes to a windows computer?
In some specific types of environments, y'all might notice information technology useful to add a static route to the routing table in Windows. Here's how to get about it.
RELATED: How to Use Traceroute to Identify Network Bug
A routing table dictates where all packets become when they go out a organization—whether that arrangement is a physical router or a PC. Well-nigh routers—including the 1 built into your Windows PC—use some form of dynamic routing, where the router is capable of selecting the best place to forward packets based on information it gets from other routers. You can see it at work if you use the traceroute command to watch the connections a packet makes every bit information technology reaches information technology'southward concluding destination.
Most routers also permit you to add a static route (one that doesn't get dynamically updated) if you desire to ever forward certain traffic to a specific router or gateway. Why? Well, most people using Windows in their home or small business concern probably won't—but this can exist useful under certain circumstances, such as:
- You accept two internet connections—maybe one for regular use and one for connecting to a piece of work network—and you want all traffic to a sure IP address range to get out over one of those connections.
- You have set up multiple subnets on your network and need to straight traffic to a particular subnet. Static routes can be particular useful in testing these types of environments.
- You lot're actually using a Windows PC as a router for your network and you want finer control over it.
If any of those utilize to y'all, read on. You'll need to dive into the Command Prompt to add a static route to the Windows routing table, just information technology'south piece of cake and we'll walk you through the steps.
View the Windows Routing Tabular array
Before you get started adding routes, it may be helpful to view the routing table first. Fire up Command Prompt by hitting Windows+X then selecting "Control Prompt (Admin)" on the Power Users card.
Note: If yous see PowerShell instead of Command Prompt on the Power Users menu, that'due south a switch that came nigh with the Creators Update for Windows ten. It's very easy to switch back to showing the Command Prompt on the Power Users carte du jour if you want, or you can give PowerShell a try. Yous tin can practice pretty much everything in PowerShell that you can practice in Control Prompt, plus a lot of other useful things.
RELATED: How to Put the Command Prompt Back on the Windows+X Power Users Menu
At the Command Prompt, type the following command and striking Enter:
route print
You'll 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.
Add a Static Route to the Windows Routing Table
To add a static route to the table, you'll type a command using the post-obit syntax:
road Add together destination_network MASK subnet_mask gateway_ip metric_cost
The subnet_mask
and metric_cost
components are optional to the command. If you don't specify a subnet mask, 255.255.255.0 volition be used automatically. If you don't specify a metric toll, a cost i greater than the 0.0.0.0 destination entry volition be used. The metric cost value is simply a cost that is relative to other costs in the table and is used when Windows decides between multiple routes that could accomplish the aforementioned destination.
And so, for case, if y'all wanted to add a route specifying that all traffic bound for the 192.168.35.0 subnet went to a gateway at 192.168.0.2 and y'all just wanted to utilise the automated metric cost, you lot would use the following command:
route Add together 192.168.35.0 MASK 255.255.255.0 192.168.0.2
If you were to use the route print
command to wait at the tabular array now, you'd run into your new static route.
That'due south all piece of cake enough, simply at that place is ane extra piddling take hold of. When you add a static route, by default it only lasts until the next fourth dimension you start Windows. The reason for this is that many companies utilize a coordinated list of static routes that gets updated adequately ofttimes. Rather than adding and updating all those routes on every machine, they simply distribute a batch script file that adds the newest routes during Windows startup. This keeps the routing table relatively uncluttered.
RELATED: How to Write a Batch Script on Windows
Yous could certainly use the batch script method yourself. Writing batch scripts isn't hard. Simply if you're simply calculation one or 2 static routes that you lot don't wait to change ofttimes, you lot can instead but add the -p
choice to the command to make the route persistent. A persistent route stays in place even when Windows starts upwards. Using the same command we used before, you could brand that route persistent with the post-obit modification:
route -p ADD 192.168.35.0 MASK 255.255.255.0 192.168.0.ii
Remove a Static Route from the Windows Routing Table
Of form, there will come a fourth dimension you lot might want to remove a static route from your table. All you accept to practise is type a command using the following syntax:
route delete destination_network
So, to delete the road we created earlier with the destination network 192.168.35.0, all we'd have to practice is blazon this command and hit Enter:
route delete 192.168.35.0
Yes, using static routes is a bit esoteric when information technology comes to managing most home and pocket-sized business networks. But if you do need to practise it, information technology's a pretty easy process. And if you don't need to do it right now, at least you know it's an selection in the hereafter.
Source: https://www.howtogeek.com/howto/windows/adding-a-tcpip-route-to-the-windows-routing-table/
0 Response to "what command is used to add static routes to a windows computer?"
Post a Comment