How to add a static route in CentOS 7?

To add a static route on CentOS 7, you can follow these steps:

  1. Open the terminal and log in as the root user.
  2. Use the following command to view the current system’s network configuration information:
  3. Show IP addresses.
  4. Add a static route using the following command:
  5. Add a route to the destination network with the specified subnet mask via the designated gateway address on the specified network interface.
  6. For instance, to add a route to the network address 192.168.0.0/24 with a gateway address of 192.168.1.1, network interface eth0, you can use the following command:
  7. Add a route for the network 192.168.0.0/24 through the interface eth0 with the gateway 192.168.1.1.
  8. Use the following command to verify if the newly added static route is effective:
  9. display IP routes
  10. To permanently save a static route, you can edit the /etc/sysconfig/network-scripts/route- file. For example, to edit the static route for the eth0 interface, you can use the following command:
  11. Open the file route-eth0 in the directory /etc/sysconfig/network-scripts using the vi editor.
  12. Add the configuration for static routes in the file, then save and exit.
  13. Restart the network service to apply the changes.
  14. Restart the network service using systemctl.

After adding a static route, the system will use this route to forward packets to the destination network address.

广告
Closing in 10 seconds
bannerAds