一、临时添加
ip route show
sudo ip route add <destination_network>/<netmask> via <gateway> dev <interface>
sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0
sudo ip route del <destination_network>/<netmask> via <gateway> dev <interface>
sudo ip route del 192.168.2.0/24 via 192.168.1.1 dev eth0
二、永久添加
要在 CentOS 中添加一条路由并使其在系统重启后仍然有效,你需要编辑 /etc/sysconfig/network-scripts/route-<interface>
文件,其中 <interface>
是你的网络接口名称,例如 eth0
。
nmcli device status
sudo touch /etc/sysconfig/network-scripts/route-eth0 sudo vi /etc/sysconfig/network-scripts/route-eth0
ADDRESS0=<destination> GATEWAY0=<gateway> NETMASK0=<netmask>
ADDRESS0=192.168.1.0 GATEWAY0=192.168.0.1 NETMASK0=255.255.255.0
sudo systemctl restart network ip route show
本文链接:https://blog.runxinyun.com/post/362.html 转载需授权!
留言0