×
How to Add a Static Route Using Powershell Cmdlet

The concept of a route is very simple, think back to the days of old telephony. To contact the desired person you would have to contact a phone operator who would physically move telephone lines to get you in contact with the other person. In essence, what the operator does is reroute your telephone line to your desired destination. The same principle is applied in computer networking as well. You use a device called a router which plays the part of the operator to properly maintain the flow of data.

Computer Routing

In computing, a route refers to data packets traveling on a network. These are generally classified into these three categories. They are default, dynamic, and static routing. These categories dictate which path the data will take from the source to the destination. Utilizing the best form of routing is paramount in optimizing your data transmission. The best way to check which routing type will work best for you, you will need to check the following parameters:

  • Bandwidth Bandwidth is the data transfer rate which is measured in bits per second. High transfer values such as Gb/s are preferred over lower, more archaic ones such as kb/s. Check the bandwidth capacity throughout all links in the network and the one that overall displays the highest value is the best.
  • Delay Delay specifies the latency for data to travel from one communication point to another and is measured in milliseconds. The way it is measured is either one-way or round-trip. The round-trip latency type is the preferred type since the data has to move to a specific point and then get responded to with a ping, effectively meaning you only need one point to measure it. Check the delay throughout all the links in the network and the overall lowest one is best.
  • Load Load defines the measure of which a router or network link is busy. This value can be calculated in many ways, mostly through CPU utilization and packets processed per second. Ensure that the high-traffic load values are still not stressing your system for optimal results.
  • Hop Count A hop occurs when data is passed from one communication point to the next. Your total hop count is the amount it takes for your package to go from the source to the destination. Every hop incurs additional latency so the optimal hop count will be the one with the quickest route.
  • Reliability Reliability depends on the network links themselves and how often they go down. Some networks are more stable than others, some are easily brought back up, and others are not. High reliability depends on how well you can keep up and maintain your networks.

What Is a Routing Table?

A routing table is similar to the mail system. If you want to send a letter to someone, you must first write down to who you want to send it. Then if the letter is unable to be sent directly to the recipient, it is instead moved over to multiple centers where they keep forwarding it. The same principle is applied in computing. Your data is moving across different nodes and each node needs to keep track of where to route each piece of data. The nodes can do this with the help of the routing table. The routing tables keep databases to know how to forward data.

Why Use Static Routing?

Static routing is when an administrator manually adds routes to the routing table. Since all of the routes in this network are predefined by the administrator, it is considered non-adaptive. Its load and bandwidth values are practically negligible and it provides the network with very high security. It is best suited for small to mid-sized networks since managing large networks can be difficult and would require extensive knowledge of the topology from the administrator.

What is Powershell?

Powershell is an open-source, command-line interface made by Microsoft. It is used to automate tasks and configurations with code. A cmdlet, pronounced as command-let, is a basic, single-function command in Powershell. They can either be used singularly to perform a task or in conjunction with one another to carry out more significant functions. It is important to note that cmdlets are not written in Powershell, they are written in another language, then compiled, and only then made available.

How to View the Routing Table Using Powershell

  1. Open up windows search and look for Powershell
  2. Right-click on Powershell and make sure to run it as an administrator
  3. Once Powershell is open, run the following command “route print”

How to Add a Static Route Using Powershell

The syntax to add a static route to a routing table is as follows:

route /f /p [command] [destination] [mask <netmask>] [gateway] [metric <metric>]] [if <interface>]

Here’s an explanation of what this syntax does step by step.

  • /f Clears the current routing table.
  • /p Adds a new routing table.
  • command You can use add, change, and delete commands depending on what you need.
  • destination Defines the destination network.
  • mask netmask Defines the subnet mask of your destination network.
  • gateway Defines the gateway IP address.
  • metric Identifies an integer cost metric.
  • if interface Defines the network interface name.

For example, run this syntax in Powershell to add a static route to the destination 192.168.0.1 with the subnet mask  255.255.0.0 and the following hop address 192.168.0.2:

route /p add 192.168.0.1 mask 255.255.0.0 192.168.0.2 if 0x2

Now to verify that you successfully added a new static route, type in:

route print

You should be able to see the new static route added and displayed in your routing table.

Before we end, a word about access controls, as you want to ensure that only authorized users can run these cmdlets. Manually managing access permissions can be cumbersome and error-prone, so consider using a tool like ManageEngine ADManager Plus to handle these permissions automatically, especially if you are using an AD environment.

Download a 30-day free trial.

ManageEngine ADManager Plus Start a 30-day FREE Trial

Conclusion

In this guide, we explained what a route is, and how to optimize and pick out your ideal networking route. We also explained how bandwidth, delay, load, hop count, and reliability impact your route choice. We cleared up the reasons why to use static routing over the other two types. Finally, we explained how to view and add a static route using the Powershell cmdlet. Hopefully, this guide covered the details you need to start managing your traffic.