How to configure Static Route | Windows | Linux

Hey, sometimes we have to configure a static route to connect to a network. Like routes, our host machine maintains its routing table. These routing tables are defined in the Operating System Kernel. In this article, we will discuss how we can configure a static route on different operating systems like Windows, Linux, etc.

What is Static Route

Static Route is a network route or network information, which can be configured on the router, firewall, or in Microsoft Windows, Linux to make the particular network reachable. Static Route uses next-hop IP address as a default route to reach that network. Likewise Router, also maintains their routing table, netmask, gateway, interface, and Metric to that network. By default, a default route is propagated, to the main network router or switch. The Routing Table of the Windows Operating System is given below:

static-route-on-windows-routing-table
Microsoft Windows Routing Table

As we discussed earlier in this article, a default route is present in the windows routing table. This default route has gateway 192.168.20.1, interface IP 192.168.20.209 and Metric is 25.

Recommended:  Policy Based Forwarding (PBF)- Palo Alto Networks Firewall

Steps to configure Static Route on Windows Operating System

In this session, we will configure a static route on the Windows Operating System. Steps to configure a static route on windows given below:

  • Click on Start Menu, type cmd, right-click on it and choose open as administrator and open a command prompt.
  • Type to the following command to check the current status of the routing table:
    route print
  • Now, add the following command to add a route in Windows routing table:
     route add Static_Route_IP mask Subnet_Mask_of_Route Gateway metric 30
    where Static_Route_IP is the IP address of route you want to add, Subnet_Mask_of_Route is the subnet mask of the route, and Gateway IP is the IP address of the next-hop IP address. Metric is used to define the priority of that route. Lower the matric, the higher the priority of the route. eg :
    route add 0.0.0.0 mask 0.0.0.0 192.168.20.1 metric 15
how-to-configure-static-route-in-windows
Adding a static route in windows machine
  • Now, test your Windows machine routing table:
    route print
routing-table-of-windows-machine
Windows Routing Table

So, we have successfully configured the static route in the windows machine. The route added is a default route and the gateway to that route is 192.168.20.1. However, you can see that there are various other routes available which are predefined as loopback address and other addresses.

Recommended:  EIGRP vs OSPF - 10 Differences between EIGRP & OSPF [2023]

How to configure Static Route in Linux (Ubuntu/Mint)

Now, we will configure the same static route on the Ubuntu operating system. Likewise, Windows Operating System, Routing Table of Linux operating system maintained by Kernel of the system. Below is the screenshot of the Linux Routing Table.

how-to-add-static-route-in-linux
Linux Routing Table

Steps to Configure Static Route on Linux Operating System

Here, we will discuss how we can add a static route on Linux Machine. Just follow the given steps to add a route in Linux Machine.

  • First, open your terminal using a shortcut key (Alt+Ctrl+T) or using GUI (Graphical User Interface).
  • Type the following command using root privileges:
    sudo route add -net ROUTE/ROUTE_NETMASK gw GATEWAY_IP metric METRIC
    where Route is the network you want to add and ROUTE_NETMASK is the netmask of the network. GATEWAY_IP is the IP address of the next-hop address. Like windows, Metric is used to define the priority of the route. Lower the metric higher priority of that route. So, In my case this command will be:
    sudo route add -net 192.168.20.0/24 gw 192.168.43.1 metric 25
    .
  • Now, we verify our configuration with the following command.
    ruote -n
how-to-configure-static-route-on-ubuntu
Ubuntu Routing Table

Thus, we verify that a static route of network 192.168.20.0 255.255.255.0 is configured in Linux Machine Routing Table, which is via 192.168.43.1 and its metric is 25.

Recommended:  Dynamic Routing : A Complete Guide for Beginner and Expert

Summary

In this article, we discussed how we can configure a static route on Microsoft Windows and Linux (Ubuntu/Mint) machines. However, the routing table is stored in the system kernel of both the operating system. The default route can be configured with the help of a static route.

Related Articles

Did you find this article helpful! Please leave a comment in comment box.

2 Comments

  1. If you use an FQDN as a static route next hop, that FQDN must resolve to an IP address that belongs to the same subnet as the interface you configured for the static route; otherwise, the firewall rejects the resolution and the FQDN remains unresolved.

    1. I agree with you! You can configure local DNS entry for the next-hop FQDN. If you are using Linux just access /etc/hosts and configure the FQDN! Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *