How can static routes be added in CentOS 7?

There are two ways to add a static route on CentOS 7: one is to use the “ip route add” command to temporarily add a static route, and the other is to edit the network configuration file to permanently add a static route.

The method for temporarily adding a static route is as follows:

  1. Use the “sudo” command to add a route for the target network with the subnet mask, pointing to the gateway IP.
  2. Add a route for the 192.168.1.0/24 network through the gateway 192.168.0.1 using sudo.
  3. remove the specified target network/subnet mask from the IP routing table
  4. Delete the route for the network 192.168.1.0/24 using sudo.

The method to permanently add a static route is as follows:

  1. route configuration file for the network card
  2. Route configuration for the network interface eth0 can be found in the file /etc/sysconfig/network-scripts/route-eth0.
  3. Gateway IP Address/Network Mask
  4. 192.168.1.0 with a subnet mask of 255.255.255.0 and IP address 192.168.0.1
  5. Restart the network using systemctl command.

You can add a static route on CentOS 7 by using the method above.

bannerAds