Routing, a term commonly used in networking, is the process of selecting the most optimal path for a data packet to travel across networks. Broadly speaking, routing can be static or dynamic. In static routing, the route for a data packet is configured manually or entered each time a data packet travels across networks. Dynamic routing, as you may have guessed, is the automatic routing of data packets.
In this article, we'll focus only on static routing to understand how it works. Also, there are many ways to add a static route, but in this article, we'll talk about how you can do it using a PowerShell cmdlet.
What is Static Routing?
Routing is a complex process as it involves routing every data packet through the appropriate channels as it traverses from its source to destination. This is often done based on a set of rules or protocols that determine the most optimal path for a data packet under different circumstances. These rules are contained in a routing table.
What's a Routing Table?
A routing table is nothing but a set of entries that tell a router where it should redirect the packets that come to it. A routing table looks something like this:
As you can see, the routing table contains the port and the next-hop destination for a packet. Essentially, a router looks at the routing table and accordingly, transfers the packets.
In static routing, these entries in the routing table are fixed and don't change automatically. These entries are entered manually by an IT admin, and hence can be changed only when the organization deems it necessary.
Just to understand the difference, dynamic routing is the process where a router determines the next best path for a packet based on the prevailing conditions such as traffic levels and available communication paths. Also known as adaptive routing, this process is not fixed and the router makes a decision on-the-fly.
A mere glance at the two routing options clearly shows that dynamic routing is far more flexible and has the potential to make the optimum use of network paths when compared to static routing. In such a case, why even use static routing in the first place?
Advantages of Static Routing
Static routing has many advantages and hence, works well in many scenarios. Some of the advantages are:
One of the biggest advantages of static routing is its impact on the existing resources. Since it requires only a minimum amount of CPU usage from the router, it does not add to the cost of operations. All that you need is one router that reads the routing table and sends the packets along the predetermined route. Even the routers don't have to be advanced for this routing. In all, static routing is the choice if you're money-strapped and can't afford to spend on smart routers.
The other big reason for companies to opt for static routing is the control they have over the entire routing path. Your IT admin determines the optimal path and the data packet simply travels along it. At any point, your IT admin will know the path in case something goes wrong. You don't have the same level of control in dynamic routing as the path is determined by the router, and this could change every time depending on the prevailing conditions.
Simple to Configure
Configuring a static route is simple and doesn't require a large team. A single individual can handle it for you, especially if you have only a small network. Further, the configuration process is simple and can be set up within just a few minutes. All this means your organization saves time, effort, and money when you choose static over dynamic routing.
That said, static routing comes with its share of disadvantages too, which are:
- No flexibility, and can impact the data packets, especially when there are problems in a certain path.
- There's always a possibility for human errors.
- No fault tolerance.
- Since the IT admin has to configure each router manually, it can add to his/her workload.
Despite these disadvantages, static routing is used extensively across many use cases. Let's now look at a few scenarios where they can come in handy.
Static Routing Use-Cases
Static routing is used extensively across homes and enterprises today because of its benefits and low overhead costs. Let's now see a few scenarios where they come in handy.
- Setting the Default Route A default route is a configuration that establishes the path that a data packet takes when there is no specific address for its next hop. Often, the default route is to reach a router with packet filtering and firewall capabilities. Static routing makes it easy to define an exit point when there are no exit points.
- Small Networks Static routing works well for small networks that often have to choose only from a handful of paths. Since this routing consumes only minimal resources and is easy to implement, they are an ideal choice for small businesses.
- Redundancy and Backup Though large organizations prefer to use dynamic routing because of its many benefits, most of them also use static routing as a backup that the data packets can fall back on in case of any issues with the router's dynamic routing capabilities. In this sense, static routing is the safer and failsafe backup for dynamic routing failures.
- Redistribution Static routing is the easiest choice when you want to transfer routing information from one protocol to the other. Also known as routing redistribution, this transfer of data is simple and easy when you choose static routing.
Thus, static routing is predictable, provides complete control, operates with little overhead, and is highly efficient for small networks and organizations.
Now that you know all about static routing, it's time to see how you can add or delete static routes to a router. There are many ways to add a static route, but we will see how you can do it with a PowerShell cmdlet, as this is the quickest and easiest way to add a static route. Of course, you can follow this method only if you have some familiarity with PowerShell cmdlets and scripting knowledge.
Adding a Static Route Using PowerShell Cmdlets
In PowerShell, cmdlets are code snippets that carry out a particular task. From a user/programmer's standpoint, it saves coding time and effort.
To add a static route, the “route” cmdlet is used. It takes the following parameters.
- /p – Adds an entry to the routing table.
- Command – Depicts your action, which can be addition, change, or deletion.
- Destination – Specifies the destination.
- Gateway – Specifies the gateway's IP address.
- Mask – Determines the subnet mask of the destination
- /f – Clears the routing table
- If – Name of the interface
Now, let's see an example.
route /p add 18.104.22.168 mask 255.255.255.255 22.214.171.124
The above command adds a static route to 126.96.36.199 with the subnet mask 255.255.255.255. The next hop address for packets that come to this subnet mask is 188.8.131.52.
You can always check if this route is added to the table with the command, “route print”. This command displays the routing table and you can see the entry you just added.
To delete this route, simply replace the action parameter like this:
route /p delete 184.108.40.206 mask 255.255.255.255 220.127.116.11
You can also create a new IP route with the New-NetRoute cmdlet. It takes the following parameters.
- -AddressFamily: This can be either IPv4 or IPv6, depending on how your network is set up.
- -CimSession: Used if you want to add an IP route from a remote computer or session.
- DestinationPrefix: This is a required value and depicts the destination IP route.
- -NextHop: Specifies the next hop destination for a packet.
- -Protocol: Specifies the type of routing protocol.
- -InterfaceIndex: This is a required parameter and specifies the index value of a network interface.
Here's an example of how you can use this cmdlet.
New-NetRoute -DestinationPrefix “18.104.22.168/12” -InterfaceIndex 23 -NextHop 22.214.171.124
This command adds an entry to the routing table for the interface that has a value of 23. It specifies 126.96.36.199 as the next hop for the data packets coming to 188.8.131.52/12.
This cmdlet gets information about one or more IP routes from a routing table. It also comes with many parameters to filter the search results.
To get all the routes in a routing table, simply type “Get-NetRoute”. You can either filter the results manually or add parameters to do that automatically. For example, if you execute “Get-NetRoute -AddressFamily IPv6”, you'll see all the routes that are related to IPv6.
In all, these PowerShell cmdlets ease your task of viewing, adding, and deleting entries from a routing table.
Static routes are a part of the routing process that sends data packets from one destination to another. These routes are fixed and don't change based on prevailing factors like traffic and bandwidth. Often, the static routes are manually entered or configured by IT admins, and the same can be changed or deleted manually when needed.
Though there are many ways to add and delete these static routes, PowerShell is the easiest option, thanks to its cmdlets that handle all the required functionality for you. We hope the above-mentioned cmdlets come in handy for you to manage your static routes.