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:
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 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:
- Now, add the following command to add a route in Windows routing table:
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 Static_Route_IP mask Subnet_Mask_of_Route Gateway metric 30
route add 0.0.0.0 mask 0.0.0.0 192.168.20.1 metric 15
- Now, test your Windows machine 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.
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.
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:
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 ROUTE/ROUTE_NETMASK gw GATEWAY_IP metric METRIC
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.
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.
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.
Did you find this article helpful! Please leave a comment in comment box.