Cheap VPS host selection
Provide server host evaluation information

The method of configuring static routes in Centos8

The method to configure static routes on CentOS 8 is as follows:

  1. Open the terminal and log in as root.
  2. Use the following command to view the configuration of the system's current routing table:
 ip route show
  1. Determine the target network and next hop gateway of the static route to be added. For example, suppose the static route to be added is to the target network 192.168.1.0/24 , the next hop gateway is 192.168.0.1
  2. Use the following command to add a static route:
 ip route add 192.168.1.0/24 via 192.168.0.1

Among them, 192.168.1.0/24 Is the network address and subnet mask of the target network, 192.168.0.1 Is the IP address of the next hop gateway.

  1. Verify whether the static route is successfully added and can be used again ip route show Command to view the configuration of the route table and ensure that the new static route has been added.
  2. To make the static route persistent, you need to write the configuration to /etc/sysconfig/network-scripts/route-<interface> In file( <interface> Is the name of the network interface). For example, suppose you want to write a static routing configuration to enp0s3 Interface, you can use the following commands:
 echo "192.168.1.0/24 via 192.168.0.1 dev enp0s3" >> /etc/sysconfig/network-scripts/route-enp0s3

Ensure that <interface> Replace with the actual network interface name.

  1. Restart the network service for the configuration to take effect:
 systemctl restart network

Note: The above steps are specific to the default network configuration of CentOS 8. If you use other network management tools (such as NetworkManager), you may need to perform corresponding operations according to different configurations.

Do not reprint without permission: Cheap VPS evaluation » The method of configuring static routes in Centos8