Add Static Route in CentOS: Step-by-Step Guide
You can add a static route in CentOS by following these steps:
- Open a terminal window and log into the system as the root user.
- Use the following command to check the network configuration of the current system:
- Show the IP route.
- This will display the current routing table.
- Add a static route using the following command:
- Add a route to the destination network/subnet with the interface address.
- In this case, “destination network/subnet” refers to the IP address of the network and subnet to be added as a routing destination, while “interface address” is the network interface to be used.
- For example, to send packets with a destination network of 192.168.0.0/24 through interface eth0, you can use the following command:
- Add a route for the network 192.168.0.0/24 via the gateway 192.168.1.1 on the eth0 interface.
- To specify the IP address of the next hop router, you can change the IP address after “via” to the router’s IP address.
- Use the following command to verify whether the newly added route is successful:
- display IP routes
- This will display the updated routing table, confirming that the static route has been successfully added.
The command above is only valid for the current session. If you want to keep this route configuration after each system startup, you can add the command to the appropriate network configuration file, such as /etc/sysconfig/network-scripts/route-eth0, where eth0 is the name of the corresponding network interface.