Configuring routes in Linux/Windows and changing priority of route by changing metric(Windows)
Lets see the lab scenario(INE lab-Find the Secret Server):
Here there are total 5 networks:
(A) Adding Routes
a) Lets first see our current routing table
b) As you can see we are already having routes to 192.168.241.0/24 and 172.16.88.0/24, that’s why we are able to access webservers.
c) Now secret network(192.168.222.0/24) is also connected to the router but it cannot be accessed as we do not have route for this.
d) In this case we can add a route manually in our windows routing table.
route ADD <destination_network> MASK <subnet_mask> <gateway_ip> metric_costroute ADD 192.168.222.0 MASK 255.255.255.0 10.175.34.1
e) Now if we again see our routing table. We can see that our newly added route is there:
f) Now we should be able to access secret web server and indeed we can:
(B) Changing priority of routes by changing metric
Lower the metric value means higher the priority. We will be seeing a scenario in which we are having 2 interfaces connected to internet 1) Ethernet and 2)Wi-Fi. By default Windows gives more priority to ethernet, therefore its metric has lower value as compared to that of Wi-Fi, but what if we want to use Wi-Fi for all the internet traffic fortunately I was having the same requirement and overcome this by changing the metric of default route of Wi-Fi route.
220.127.116.11 is gateway address for Ethernet interface and 18.104.22.168 is the IP address assigned to the interface by DHCP server of router. Similarly for WLAN interface 192.0.0.1 is gateway address and 192.0.0.3 is the IP address assigned to the Wi-Fi interface. Here is the ipconfig output just for confirmation:
a) Now for changing priority we first need to know the Interface. We can use any of these commands for this:
get-wmiobject win32_networkadapter | select netconnectionid, name, InterfaceIndex, netconnectionstatusnetsh interface ipv4 show interfacesGet-NetAdapter
b) Changing the metric(Run as administrator):
Set-NetIPInterface -InterfaceIndex 12 -InterfaceMetric 15
(C) Disabling priority of ethernet interface(Prevents Wi-Fi disconnection after connecting Ethernet)
Just disable Priority & VLAN option in Interface advanced options
1. Go to network and sharing center in control panel.
2. Select change adapter settings
3. Right click on your Ethernet device and select properties on popup menu.
4. In properties menu, click configure button.
5. When configure menu, select advanced tab.
6. In advanced menu, under property list, look for “Priority & Vlan” and select it.
7. Look in value list to the right and select disable toggle.
8. Click Ok, on your way back out of menus and wait 15 seconds until system updates new value.
Steps are exactly same. Only commands are different.
ip route add 192.168.222.0/24 via 10.175.34.1
c) New route added:
route del -net 192.168.222.0 gw 10.175.34.1 netmask 255.255.255.0 dev eth0
Thank you for reading!
Author: Prabhsimran (https://www.linkedin.com/in/pswalia2u/)