In this guide, we explain how to configure static IP routing on a Linux system, enabling communication between distinct networks. This tutorial is particularly useful in scenarios where you have separate networks that require interconnectivity using a dedicated routing device. Imagine two computers, Computer A and Computer B, each connected to its own network—Network 1 and Network 2, respectively. By default, these computers cannot communicate with each other because they reside on isolated networks. Now, consider introducing a third computer, Computer C, which is physically connected to both networks by having two IP addresses (one on each network). Computer C can effectively act as a router to forward data packets between the two networks. Even after interconnecting the networks via Computer C, Computer A will be unaware of how to reach hosts on Network 2 (for example, 192.168.0.1) without proper route configuration. To bridge the communication gap, you need to add a static route on Computer A. Suppose Computer A has an IP address of 10.0.0.1, and you need to reach the network 192.168.0.0/24. You can specify that packets destined for that network should go through the gateway at 10.0.0.100, which is Computer C’s IP address on the interface connected to Network 1. Remember to update these IP addresses to match your actual network configuration.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Adding Static Routes
You can add a static route using the following command:enp0s3, modify the command accordingly:
Routes added using the ip command are temporary and will be lost after a reboot. This method is ideal for immediate testing and verification of new routing configurations.
Making Routes Permanent
To ensure that your routing configurations persist after a reboot, integrate them into your system’s network configuration. Start by identifying the active NetworkManager connection using the following command:enp0s3), add a persistent route to direct all traffic destined for the network 192.168.0.0/24 through Computer C at 10.0.0.100.
Keep in mind that NetworkManager will not automatically apply these changes until you either reboot or manually reload the connection settings. To update the settings immediately, run:
Persistent routing configurations vary depending on your Linux distribution. Consult your distribution’s documentation for specific instructions if adjustments are needed.
Conclusion
This article has covered both temporary and permanent methods of configuring static IP routes in Linux. We discussed how to add and delete routes using theip command for quick testing, as well as how to make changes permanent by updating NetworkManager settings. These techniques are essential for managing inter-network communication in complex deployments.
We hope this guide on Linux networking aids in your system configuration and enhances your understanding of static routing.
For further reading, please explore these resources: