[root@control ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0192.168.3.2540.0.0.0 UG 10300 ens161
10.88.0.00.0.0.0255.255.0.0 U 000 cni0
192.168.3.00.0.0.0255.255.255.0 U 10300 ens161
192.168.3.2540.0.0.0255.255.255.255 UH 000 ens161
192.168.122.00.0.0.0255.255.255.0 U 000 virbr0
二、激活网卡
1.查看所有物理网卡
[root@control ~]# nmcli device
DEVICE TYPE STATE CONNECTION
ens161 ethernet connected ens161
cni0 bridge connected cni0
virbr0 bridge connected virbr0
ens160 ethernet disconnected --
vethbf044fd9 ethernet unmanaged --
lo loopback unmanaged --
virbr0-nic tun unmanaged --
2.连接新增网卡
[root@control ~]# nmcli connection up ens160
Connection successfully activated(D-Bus active path:/org/freedesktop/NetworkManager/ActiveConnection/10)
3.查看IP
ifconfig ens160
三、系统的路由管理
1.添加一条网关路由
route add -net 0.0.0.0 netmask 255.255.255.255 dev ens37
2.设置默认网关
route add default gw 192.168.243.2
[root@192 user]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.00.0.0.0255.255.255.255 UH 000 ens37
0.0.0.0192.168.243.20.0.0.0 UG 000 ens37
0.0.0.0192.168.3.2540.0.0.0 UG 10000 ens33
10.88.0.00.0.0.0255.255.0.0 U 000 cni-podman0
192.168.3.00.0.0.0255.255.255.0 U 10000 ens33
192.168.122.00.0.0.0255.255.255.0 U 000 virbr0
192.168.243.00.0.0.0255.255.255.0 U 10100 ens37
3.删除默认网关
route del default gw 192.168.243.2
4.使用route命令删除静态路由
route del -net 192.168.1.0 netmask 255.255.255.0 dev ens37
四、配置路由优先级
1.多个网关存在时,无法上网
[root@192 user]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.00.0.0.0255.255.255.255 UH 000 ens37
0.0.0.0192.168.243.20.0.0.0 UG 000 ens37
0.0.0.0192.168.3.2540.0.0.0 UG 10000 ens33
10.88.0.00.0.0.0255.255.0.0 U 000 cni-podman0
192.168.3.00.0.0.0255.255.255.0 U 10000 ens33
192.168.122.00.0.0.0255.255.255.0 U 000 virbr0
192.168.243.00.0.0.0255.255.255.0 U 10100 ens37
[root@192 user]# ping www.baidu.com
^C
[root@192 user]# ping www.baidu.com -c4
PING www.a.shifen.com(112.80.248.76)56(84) bytes of data.
From 192.168.243.140(192.168.243.140) icmp_seq=1 Destination Host Unreachable
From 192.168.243.140(192.168.243.140) icmp_seq=2 Destination Host Unreachable
From 192.168.243.140(192.168.243.140) icmp_seq=3 Destination Host Unreachable
From 192.168.243.140(192.168.243.140) icmp_seq=4 Destination Host Unreachable
--- www.a.shifen.com ping statistics ---4 packets transmitted,0 received,+4 errors,100% packet loss, time 2999ms
pipe 4[root@192 user]#
2.添加路由时指定优先级
[root@192 user]# ip route add default via 192.168.243.2 metric 99[root@192 user]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.00.0.0.0255.255.255.255 UH 000 ens37
0.0.0.0192.168.243.20.0.0.0 UG 000 ens37
0.0.0.0192.168.243.20.0.0.0 UG 9900 ens37
0.0.0.0192.168.3.2540.0.0.0 UG 10000 ens33
10.88.0.00.0.0.0255.255.0.0 U 000 cni-podman0
192.168.3.00.0.0.0255.255.255.0 U 10000 ens33
192.168.122.00.0.0.0255.255.255.0 U 000 virbr0
192.168.243.00.0.0.0255.255.255.0 U 10100 ens37
3.添加某条静态路由
[root@192 user]# ip route add 192.168.120.0/24 via 192.168.243.2[root@192 user]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0192.168.243.20.0.0.0 UG 000 ens37
0.0.0.0192.168.243.20.0.0.0 UG 9900 ens37
0.0.0.0192.168.3.2540.0.0.0 UG 10000 ens33
10.88.0.00.0.0.0255.255.0.0 U 000 cni-podman0
192.168.3.00.0.0.0255.255.255.0 U 10000 ens33
192.168.120.0192.168.243.2255.255.255.0 UG 000 ens37
192.168.122.00.0.0.0255.255.255.0 U 000 virbr0
192.168.243.00.0.0.0255.255.255.0 U 10100 ens37
4.删除静态路由
ip route del default via 192.168.243.2
5.指定上网出口网关优先级
[root@192 user]# ip route add default via 192.168.3.254 metric 98[root@192 user]# ping www.baidu.com
PING www.a.shifen.com(112.80.248.76)56(84) bytes of data.64 bytes from 112.80.248.76(112.80.248.76): icmp_seq=1 ttl=55 time=32.3 ms
64 bytes from 112.80.248.76(112.80.248.76): icmp_seq=2 ttl=55 time=33.0 ms
64 bytes from 112.80.248.76(112.80.248.76): icmp_seq=3 ttl=55 time=34.0 ms
64 bytes from 112.80.248.76(112.80.248.76): icmp_seq=4 ttl=55 time=34.2 ms
^C
--- www.a.shifen.com ping statistics ---4 packets transmitted,4 received,0% packet loss, time 3004ms
rtt min/avg/max/mdev =32.395/33.442/34.268/0.782 ms
[root@192 user]#