CentOS Linux: Add Static Routing

www.lautt‮c.iru‬om
CentOS Linux: Add Static Routing

To add a static route on CentOS Linux, you can use the route command or edit the /etc/sysconfig/network-scripts/route-interface file.

  1. To add a static route using the 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.

  1. To add a static route permanently, you can edit the /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.

  1. Restart the network service to apply the changes:
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.

Created Time:2017-10-16 14:38:40  Author:lautturi