MacOS 双网卡上内外网的方法
首先先设置网卡优先级
然后获取网卡接口
$ netstat -rt
Routing tables
Internet:
Destination Gateway Flags Netif Expire
default 192.168.0.1 UGSc en9
default 10.16.135.1 UGScI en11
1 198.18.0.1 UGSc utun3
2/7 198.18.0.1 UGSc utun3
4/6 198.18.0.1 UGSc utun3
8/5 198.18.0.1 UGSc utun3
10.16/16 link#13 UCS en11 !
10.16.135.1/32 link#13 UCS en11 !
10.16.135.1 0:0:5e:0:1:87 UHLWIir en11 1190
10.16.135.10 44:37:e6:52:7c:9b UHLWI en11 1160
10.16.135.46/32 link#13 UCS en11 !
10.16.135.46 0:e:c6:6c:7c:49 UHLWI lo0
10.16.135.56 0:11:9:3:b3:9d UHLWI en11 1108
10.16.135.128 0:15:58:e0:cf:51 UHLWI en11 1127
10.16.135.246 0:24:81:84:50:65 UHLWI en11 916
10.16.149.34 b8:ae:ed:93:da:b0 UHLWI en11 1158
16/4 198.18.0.1 UGSc utun3
32/3 198.18.0.1 UGSc utun3
64/2 198.18.0.1 UGSc utun3
127 localhost UCS lo0
localhost localhost UH lo0
128.0/1 198.18.0.1 UGSc utun3
169.254 link#21 UCS en9 !
169.254 link#13 UCSI en11 !
192.168.0 link#21 UCS en9 !
192.168.0.1/32 link#21 UCS en9 !
192.168.0.1 4c:bc:98:0:dc:b8 UHLWIir en9 1157
192.168.0.100/32 link#21 UCS en9 !
198.18.0/16 198.18.0.1 UGSc utun3
198.18.0.1 198.18.0.1 UH utun3
224.0.0/4 link#21 UmCS en9 !
224.0.0/4 link#13 UmCSI en11 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI en11
239.255.255.250 1:0:5e:7f:ff:fa UHmLWI en9
255.255.255.255/32 link#21 UCS en9 !
255.255.255.255/32 link#13 UCSI en11 !
我们就可以设置路由转发了
1.通过网关转发的方式
$ sudo route delete -net 158.220.155.188
$ sudo route -n add -net 158.220.155.188 158.223.13.254
$ sudo route delete -net 158.220.21.39
$ sudo route -n add -net 158.220.21.39 158.223.13.254
2.通过网卡转发的方式
$ sudo route delete -net 158.220.155.188
$ sudo route add -net 158.220.155.188 -netmask 255.255.255.0 -interface en10
列出现有路由列表
$ sudo netstat -nr
Mac 重启后路由列表就会清空,也可以通过Automator
来自动设置