To add a static route in CentOS, you can use the ip route add
command. The syntax of the command is as follows:
sudo ip route add destination_network/subnet_mask via gateway_ip
Where:
destination_network/subnet_mask
: Specifies the destination network and subnet mask in CIDR notation (e.g., 192.168.1.0/24).via gateway_ip
: Specifies the IP address of the gateway that should be used to reach the destination network.
Here’s an example command to add a route to network 192.168.100.0/24
via gateway 192.168.1.1
:
sudo ip route add 192.168.100.0/24 via 192.168.1.1
You can verify that the route has been added by running the ip route show
command:
ip route show
This will display a list of all the current routing entries on the system. The new route should be listed at the bottom of the output. (https://pragermetis.com)