OSX Yosemite - 如何添加具有两个默认网关的路由


3

我在OSX优胜美地,我有两个不同的有效连接...... - WIFI(en0) - 连接USB(en7)

SnakeBook:~ root# netstat -nr
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc           14        4     en0
default            192.168.42.129     UGScI           0        0     en7

现在......我需要添加一条路线来通过网络连接浏览一些网站。例如,我想使用en7在speedtest.net上运行speedtest。我的DNS(使用OpenDNS的192.168.1.1)以这种方式解决了Speedtest ...

SnakeBook:~ root# nslookup speedtest.net
Server:     192.168.1.1
Address:    192.168.1.1#53

Non-authoritative answer:
Name:   speedtest.net
Address: 216.146.46.10
Name:   speedtest.net
Address: 216.146.46.11

现在......我添加了两条路线:

SnakeBook:~ root# route add -host 216.146.46.10 192.168.42.129
add host 216.146.46.10: gateway 192.168.42.129
SnakeBook:~ root# route add -host 216.146.46.11 192.168.42.129
add host 216.146.46.11: gateway 192.168.42.129
SnakeBook:~ root# netstat -nr
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc           14        4     en0
default            192.168.42.129     UGScI           0        0     en7
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              3    13259     lo0
169.254            link#4             UCS             0        0     en0
169.254            link#12            UCSI            0        0     en7
192.168.1          link#4             UCS             3        0     en0
192.168.1.1/32     link#4             UCS             1        0     en0
192.168.1.1        0:1c:f0:38:4e:49   UHLWIir        17      509     en0   1199
192.168.1.4/32     link#4             UCS             0        0     en0
192.168.1.7        30:59:b7:a6:3b:cf  UHLWI           0        0     en0   1155
192.168.1.8        64:9a:be:ee:43:93  UHLWI           0        0     en0   1105
192.168.1.255      ff:ff:ff:ff:ff:ff  UHLWbI          0        3     en0
192.168.42         link#12            UCS             1        0     en7
192.168.42.114/32  link#12            UCS             1        0     en7
192.168.42.129/32  link#12            UCS             1        0     en7
192.168.42.129     76:0:b4:4:cc:38    UHLWIir         3        2     en7    713
192.168.42.255     ff:ff:ff:ff:ff:ff  UHLWbI          0        3     en7
216.146.46.10      192.168.42.129     UGHS            0        0     en7
216.146.46.11      192.168.42.129     UGHS            0        0     en7

并在speedtest.net上尝试traceroute似乎工作正常。

SnakeBook:~ root# traceroute speedtest.net
traceroute: Warning: speedtest.net has multiple addresses; using 216.146.46.11
traceroute to speedtest.net (216.146.46.11), 64 hops max, 52 byte packets
 1  192.168.42.129 (192.168.42.129)  0.760 ms  0.192 ms  0.366 ms
 ...
 ...    
12  * *^C

问题是我使用浏览器时。使用浏览器,流量总是通过en0 gw而不是en7 gw。这个问题是由“两个”默认网关引起的吗?

我试图删除en7 gw,但它总是删除我的en0 gw:

SnakeBook:tmp root# netstat -nr | grep default
default            192.168.1.1        UGSc           30        4     en0
default            192.168.42.129     UGScI           0        0     en7
SnakeBook:tmp root# 
SnakeBook:tmp root# 
SnakeBook:tmp root# route delete default 192.168.42.129
delete net default: gateway 192.168.42.129
SnakeBook:tmp root# 
SnakeBook:tmp root# 
SnakeBook:tmp root# netstat -nr | grep default
default            192.168.42.129     UGScI           0        0     en7

有什么建议吗?

谢谢!

Answers:


3

我正在解决类似的问题:如何在Mac OS X下设置特定于路由的界面指标,并偶然发现问题的答案。Mac OS X的作用是这样的:因为它看到了两条到达目标的路由,所以它选择了具有最高优先级的路由(正如在这个很棒的答案中所讨论的那样:https//superuser.com/a/525592/169461)。当然,改变每条路线的优先级并不是你想要的。

您要做的是使用指定的接口添加到此特定IP的路由:

sudo route add -host 216.146.46.10 -iface en7

请注意,重新启动后,此路由将再次消失。我还没有能够在OS X Yosemite中保留任何静态路由(尝试使用/ Library / LaunchAgent中的.plist文件的方法,如下所述:https://www.jverdeyen.be/mac/persistent-static-routes -mac-os-x /)。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.