When we face the situation where different subnet cannot be accessed through your default gateway. So, we have to add static route to help traffic get route in centos.
For temporary route, can use this command:
user@server:~# ip route add 172.16.15.0/24 via 10.0.0.101 dev ens192
ip route add
= Command to add new static routing.172.16.15.0
= Subnet interface destination/20
= Subnet Mask10.0.0.101
= Gateway interface that want to route.dev eth1
= Network Interface ens192
To make it permanent system or network settings restart not lost config, create a route-ifname
file for an interface through which the subnet is accessed. In my case, our server use ens192
.
user@server:~# vim /etc/sysconfig/network-scripts/route-ens192
Add the line with the network settings for the other subnet:
172.16.15.0/24 via 10.0.0.101 dev ens192
Save the file and restart network service. Or you can reboot for refresh.
And then, how to remove static route. Just type this command below.
user@server:~# ip route del 172.16.15.0/24
So simple right? add static route in centos. What if static route in windows? Here is article How to Add Static IP Route on Windows.
May be it’s helpful, please feel free to leave a comment if you have any questions and I’ll appreciate it.