Fork me on GitHub
代码改变世界

centos7 双网卡配置 默认数据走外网 指定ip上内网

2021-01-05 20:03  freefei  阅读(1205)  评论(0编辑  收藏  举报
[root@B4-05-5D-54-21-D6 network-scripts]# route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         homerouter.cpe  0.0.0.0         UG    107    0        0 enp26s0f0
default         gateway         0.0.0.0         UG    108    0        0 enp26s0f1
10.42.0.0       0.0.0.0         255.255.0.0     U     0      0        0 docker0
169.254.169.250 0.0.0.0         255.255.255.255 UH    0      0        0 docker0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     0.0.0.0         255.255.255.0   U     108    0        0 enp26s0f1
192.168.8.0     0.0.0.0         255.255.255.0   U     107    0        0 enp26s0f0
[root@B4-05-5D-54-21-D6 network-scripts]# route add -net 192.168.8.0/24 gw 192.168.8.1 enp26s0f0  # 上外网
[root@B4-05-5D-54-21-D6 network-scripts]# route add -net 192.168.0.0/24 gw 192.168.0.1 enp26s0f1  # 上内网
[root@B4-05-5D-54-21-D6 network-scripts]# route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         homerouter.cpe  0.0.0.0         UG    107    0        0 enp26s0f0
default         gateway         0.0.0.0         UG    108    0        0 enp26s0f1
10.42.0.0       0.0.0.0         255.255.0.0     U     0      0        0 docker0
169.254.169.250 0.0.0.0         255.255.255.255 UH    0      0        0 docker0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     gateway         255.255.255.0   UG    0      0        0 enp26s0f1
192.168.0.0     0.0.0.0         255.255.255.0   U     108    0        0 enp26s0f1
192.168.8.0     homerouter.cpe  255.255.255.0   UG    0      0        0 enp26s0f0
192.168.8.0     0.0.0.0         255.255.255.0   U     107    0        0 enp26s0f0
[root@B4-05-5D-54-21-D6 network-scripts]# route add -net 10.72.83.0/24 gw 192.168.0.1 enp26s0f1  # 指定该网段走内网
[root@B4-05-5D-54-21-D6 network-scripts]# route add default gw 192.168.8.1 enp26s0f0  # 指定默认路由 网卡
[root@B4-05-5D-54-21-D6 network-scripts]# route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         homerouter.cpe  0.0.0.0         UG    0      0        0 enp26s0f0
default         homerouter.cpe  0.0.0.0         UG    107    0        0 enp26s0f0
default         gateway         0.0.0.0         UG    108    0        0 enp26s0f1
10.42.0.0       0.0.0.0         255.255.0.0     U     0      0        0 docker0
10.72.83.0      gateway         255.255.255.0   UG    0      0        0 enp26s0f1
169.254.169.250 0.0.0.0         255.255.255.255 UH    0      0        0 docker0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     gateway         255.255.255.0   UG    0      0        0 enp26s0f1
192.168.0.0     0.0.0.0         255.255.255.0   U     108    0        0 enp26s0f1
192.168.8.0     homerouter.cpe  255.255.255.0   UG    0      0        0 enp26s0f0
192.168.8.0     0.0.0.0         255.255.255.0   U     107    0        0 enp26s0f0
[root@B4-05-5D-54-21-D6 network-scripts]# ping baidu.com
PING baidu.com (39.156.69.79) 56(84) bytes of data.
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=47 time=74.9 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=47 time=84.7 ms
^C
--- baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 74.914/79.821/84.728/4.907 ms
[root@B4-05-5D-54-21-D6 network-scripts]# ping 192.168.8.1
PING 192.168.8.1 (192.168.8.1) 56(84) bytes of data.
64 bytes from 192.168.8.1: icmp_seq=1 ttl=64 time=0.625 ms
64 bytes from 192.168.8.1: icmp_seq=2 ttl=64 time=0.674 ms
^C
--- 192.168.8.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1006ms
rtt min/avg/max/mdev = 0.625/0.649/0.674/0.035 ms
[root@B4-05-5D-54-21-D6 network-scripts]# ping 192.168.8.181
PING 192.168.8.181 (192.168.8.181) 56(84) bytes of data.
^C
--- 192.168.8.181 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

[root@B4-05-5D-54-21-D6 network-scripts]# ping 192.168.8.104
PING 192.168.8.104 (192.168.8.104) 56(84) bytes of data.
^C
--- 192.168.8.104 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1043ms

[root@B4-05-5D-54-21-D6 network-scripts]# ping 192.168.8.103
PING 192.168.8.103 (192.168.8.103) 56(84) bytes of data.
64 bytes from 192.168.8.103: icmp_seq=1 ttl=64 time=0.067 ms
64 bytes from 192.168.8.103: icmp_seq=2 ttl=64 time=0.041 ms
64 bytes from 192.168.8.103: icmp_seq=3 ttl=64 time=0.064 ms
^C
--- 192.168.8.103 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2078ms
rtt min/avg/max/mdev = 0.041/0.057/0.067/0.013 ms
[root@B4-05-5D-54-21-D6 network-scripts]# ping 192.168.8.101
PING 192.168.8.101 (192.168.8.101) 56(84) bytes of data.
^C
--- 192.168.8.101 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

[root@B4-05-5D-54-21-D6 network-scripts]# ping 10.72.83.11
PING 10.72.83.11 (10.72.83.11) 56(84) bytes of data.
64 bytes from 10.72.83.11: icmp_seq=1 ttl=62 time=13.6 ms
64 bytes from 10.72.83.11: icmp_seq=2 ttl=62 time=22.1 ms
64 bytes from 10.72.83.11: icmp_seq=3 ttl=62 time=17.5 ms
64 bytes from 10.72.83.11: icmp_seq=4 ttl=62 time=11.7 ms


参考

@ https://github.com/ranmufei

校友通微信小程序

校友通微信小程序