当前网卡情况
[root@lys-kb0611001 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:0a:2d:97:dc txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.6.10.27 netmask 255.255.255.0 broadcast 10.6.10.255
inet6 fe80::f816:3eff:fe37:88b3 prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:37:88:b3 txqueuelen 1000 (Ethernet)
RX packets 136806048 bytes 76283416866 (71.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 27823 bytes 94915324 (90.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.6.8.144 netmask 255.255.254.0 broadcast 10.6.9.255
inet6 fe80::f816:3eff:fed2:7664 prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:d2:76:64 txqueuelen 1000 (Ethernet)
RX packets 98934000 bytes 30041180413 (27.9 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 67357 bytes 15304380 (14.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 626577 bytes 234823805 (223.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 626577 bytes 234823805 (223.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
路由表
[root@lys-kb0611001 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.6.10.254 0.0.0.0 UG 100 0 0 eth0
0.0.0.0 10.6.9.254 0.0.0.0 UG 101 0 0 eth1
10.0.31.174 10.6.9.254 255.255.255.255 UGH 0 0 0 eth1
10.0.31.174 0.0.0.0 255.255.255.255 UH 0 0 0 eth1
10.6.8.0 0.0.0.0 255.255.254.0 U 101 0 0 eth1
10.6.10.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
169.254.169.254 10.6.10.2 255.255.255.255 UGH 100 0 0 eth0
169.254.169.254 10.6.8.205 255.255.255.255 UGH 101 0 0 eth1
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
ip route show
[root@lys-kb0611001 ~]# ip route show
default via 10.6.10.254 dev eth0 proto dhcp metric 100
default via 10.6.9.254 dev eth1 proto dhcp metric 101
10.0.31.174 via 10.6.9.254 dev eth1
10.0.31.174 dev eth1 scope link
10.6.8.0/23 dev eth1 proto kernel scope link src 10.6.8.144 metric 101
10.6.10.0/24 dev eth0 proto kernel scope link src 10.6.10.27 metric 100
169.254.169.254 via 10.6.10.2 dev eth0 proto dhcp metric 100
169.254.169.254 via 10.6.8.205 dev eth1 proto dhcp metric 101
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
添加路由
我本机的主机为10.6.1.3,因为虚拟机默认走的eth0,所以我打算和10.6.1.3 使用网卡eth1,有如下方式,设置ip或者子网
[root@lys-kb0611001 ~]# ip route get 10.6.1.3
10.6.1.3 via 10.6.10.254 dev eth0 src 10.6.10.27
cache
[root@lys-kb0611001 ~]# ip route add 10.6.1.3 via 10.6.9.254
[root@lys-kb0611001 ~]# ip route get 10.6.1.3
10.6.1.3 via 10.6.9.254 dev eth1 src 10.6.8.144
cache
[root@lys-kb0611001 ~]# ip route delete 10.6.1.3 via 10.6.9.254 dev eth1
[root@lys-kb0611001 ~]# ip route get 10.6.1.3
10.6.1.3 via 10.6.10.254 dev eth0 src 10.6.10.27
cache
删除路由
ip route delete 10.6.1.0/24 via 10.6.9.254 dev eth1