CentOS Add Route Command

‮l.www‬autturi.com
CentOS Add Route Command

To add a route to the routing table on CentOS, you can use the ip command with the route add subcommand.

For example, to add a route to the 10.0.0.0/8 network via the 192.168.1.1 gateway, you can use the following command:

sudo ip route add 10.0.0.0/8 via 192.168.1.1

This will add a route to the routing table that directs traffic to the 10.0.0.0/8 network to be sent through the 192.168.1.1 gateway.

You can also specify a device (e.g. an interface) that should be used for the route. For example, to add a route using the eth0 interface:

sudo ip route add 10.0.0.0/8 via 192.168.1.1 dev eth0

If you want the route to be automatically added when the system boots, you can add it to the /etc/sysconfig/network-scripts/route-eth0 file (replace eth0 with the appropriate interface name). The route will be automatically added when the interface is brought up.

For example, to add the route to the /etc/sysconfig/network-scripts/route-eth0 file:

echo "10.0.0.0/8 via 192.168.1.1" | sudo tee -a /etc/sysconfig/network-scripts/route-eth0

Note: The ip command is part of the iproute2 package, which is installed by default on most CentOS systems. If the ip command is not available on your system, you can install the iproute2 package using the yum or dnf package manager.

sudo yum install iproute2

or

sudo dnf install iproute2
Created Time:2017-10-16 14:38:40  Author:lautturi