Static routes are manual configurations that inform routers about the best path to reach specific destinations. They are useful when the default routing table does not have the necessary information to route traffic correctly.
In the provided scenario, direct communication between servers on the same subnet is not possible due to layer-2 traffic restrictions. To enable communication between these servers, static routes need to be established.
Creating Static Routes
The process of creating static routes varies depending on the operating system. Here’s a breakdown for each operating system:
CentOS
- Open the route-eth0 file in /etc/sysconfig/network-scripts/.
- Add the following line to the file:
192.51.100.42/32 via 192.51.100.1 dev eth0
- Save the file.
- Repeat steps 1-3 on the other server, replacing 192.51.100.42 with the IP address of the other server.
Debian/Ubuntu (until 17.04)
- Open the /etc/network/interfaces file.
- Add the following lines to the file:
up ip route add 192.51.100.42/32 via 192.51.100.1 dev eth0
down ip route del 192.51.100.42/32 via 192.51.100.1 dev eth0
- Save the file.
- Repeat steps 1-3 on the other server, replacing 192.51.100.42 with the IP address of the other server.
Ubuntu (17.10 and above)
- Open the /etc/netplan/01-netcfg.yaml file.
- Add the following lines to the file:
eth0:
routes:
- to: 192.51.100.0/25
via: 192.51.100.1
- to: 192.51.100.128/25
via: 192.51.100.1
- Save the file.
- Run the following command:
sudo netplan apply
openSUSE
- Open the /etc/sysconfig/network/routes file.
- Add the following line to the file:
192.51.100.42/32 192.51.100.1 - eth0
- Save the file.
- Repeat steps 1-3 on the other server, replacing 192.51.100.42 with the IP address of the other server.
Windows Server
- Open Command Prompt with administrative privileges.
- Enter the following command:
route -p add 192.51.100.42 mask 255.255.255.255 192.51.100.1
- Repeat step 2 on the other server, replacing 192.51.100.42 with the IP address of the other server.
Additional Notes
- The -p option in the Windows Server commands makes the route persistent across reboots.
- If you often reboot your Windows Server, it is advisable to create a .bat script to perform the step of deleting the default route automatically.
Conclusion
Static routes are a useful tool for managing network traffic. They can be used to improve network performance, increase security, and troubleshoot network problems.