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:
- Use the “sudo” command to add a route for the target network with the subnet mask, pointing to the gateway IP.
- Add a route for the 192.168.1.0/24 network through the gateway 192.168.0.1 using sudo.
- remove the specified target network/subnet mask from the IP routing table
- Delete the route for the network 192.168.1.0/24 using sudo.
The method to permanently add a static route is as follows:
- route configuration file for the network card
- Route configuration for the network interface eth0 can be found in the file /etc/sysconfig/network-scripts/route-eth0.
- Gateway IP Address/Network Mask
- 192.168.1.0 with a subnet mask of 255.255.255.0 and IP address 192.168.0.1
- Restart the network using systemctl command.
You can add a static route on CentOS 7 by using the method above.