CentOS 7/8添加永久路由

CentOS 7/8添加永久路由

查看当前路由信息

[root@ansible231 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 eth0
10.32.122.0     0.0.0.0         255.255.254.0   U     101    0        0 eth0
10.56.0.0       10.255.158.254  255.255.0.0     UG    0      0        0 ens6
10.255.158.0    0.0.0.0         255.255.255.0   U     100    0        0 ens6
10.255.159.0    10.255.158.254  255.255.255.0   UG    0      0        0 ens6

添加永久路由

nmcli con modify ens6 +ipv4.routes "192.168.1.0/24 192.168.2.1"

ens6为需配置路由的网卡
192.168.1.0/24为目标网段、子网掩码
192.168.2.1为网关

添加后重启网络服务,启动网卡

systemctl restart NetworkManager
nmcli con up ens6

查看网卡的永久路由信息

nmcli con show ens6 | grep ipv4.routes

你可能感兴趣的:(centos,服务器,linux)