How to configure Static Route | Windows | Linux

Hey, sometimes we have to configure a static route in order to connect to a network. Like routes, our host machine maintains their routing table. These routing tables are defined in 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 router, firewall or in Microsoft Windows, Linux in order to make the particular network reachable. Static Route uses next hop IP address as a default route to reach to that network. Likewise Router, they also maintain 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. Routing Table of 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.

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 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 in order 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 route and Gateway IP is the IP address of next hop IP address. Metric is used to define the priority of that route. Lower the matric, higher the priority of 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 static route in 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.

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 maintain by Kernel of the system. Below is the screenshot of 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 given steps in order to add a route in Linux Machine.

  • First, open your terminal using 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 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.

Summary

In this article, we discussed how we can configure a static route on Microsoft Windows and Linux (Ubuntu/Mint) machine. 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 static route.

Related Articles

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

Leave a Reply

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