To add a static route on CentOS Linux, you can use the route
command or edit the /etc/sysconfig/network-scripts/route-interface
file.
route
command, use the following syntax:sudo route add -net destination_network netmask netmask_value gw gateway_ip dev interface
For example, to add a route to the 10.0.0.0/8
network through the 192.168.1.1
gateway on the eth0
interface, you can use the following command:
sudo route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.1.1 dev eth0
This will add the static route to the system routing table.
/etc/sysconfig/network-scripts/route-interface
file. For example, to add a route to the 10.0.0.0/8
network through the 192.168.1.1
gateway on the eth0
interface, you can use the following steps:sudo nano /etc/sysconfig/network-scripts/route-eth0
Add the following line to the file:
10.0.0.0/8 via 192.168.1.1
Save and close the file.
sudo service network restart
After completing these steps, the static route should be added to the system routing table. You can use the route
command to verify that the static route has been added.