-
Open the terminal and log in as root. -
Use the following command to view the configuration of the system's current routing table:
ip route show
-
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 。 -
Use the following command to add a static route:
ip route add 192.168.1.0/24 via 192.168.0.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. -
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
-
Restart the network service for the configuration to take effect:
systemctl restart network