我已经阅读了很多关于这个问题的答案,但是没有一个有效(大概是因为它们是为过时的OS X版本编写的)。我如何实际与beaglebone分享我的Mac的互联网连接?
答案 0 :(得分:2)
我将假设您已成功安装必要的驱动程序,并且beaglebone会显示在您的网络接口列表中。在这种情况下,请确保您已正确配置IP地址和网络掩码。对于默认的beaglebone连接,它看起来像这样:
完成后,请确认您可以连接到beaglebone:
mac$ ssh root@192.168.7.2
Debian GNU/Linux 7
BeagleBoard.org Debian Image 2015-11-12
Support/FAQ: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian
default username:password is [debian:temppwd]
Last login: Thu Nov 12 19:06:13 2015 from mac.local
root@beaglebone:~#
您现在已准备好设置nat,以允许beaglebone共享您的网络连接。为此,首先找到与您的beaglebone关联的网络接口的名称:
$ ifconfig | grep -C 3 192.168.7.1
en9: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1486
ether 04:a3:16:ad:6c:4d
inet6 fe80::6a3:16ff:fead:6c4d%en9 prefixlen 64 scopeid 0x4
inet 192.168.7.1 netmask 0xfffffffc broadcast 192.168.7.3
nd6 options=1<PERFORMNUD>
media: autoselect
status: active
然后,激活ip forwarding并设置适当的防火墙规则:
mac$ sudo sysctl net.inet.ip.forwarding=1
net.inet.ip.forwarding: 0 -> 1
mac$ echo "nat on en0 from en9:network to any -> (en0)" | sudo pfctl -f - -e
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.
No ALTQ support in kernel
ALTQ related functions disabled
pf enabled
当然,您需要将en9替换为您在上一步中找到的接口名称。此外,如果您已启用防火墙,则需要手动将其添加到防火墙配置中。
最后,我们需要设置默认网关:
mac$ ssh root@192.168.7.1
beaglebone# route add default gw 192.168.7.1 usb0
beaglebone# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=54 time=16.6 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=54 time=20.5 ms
如果一切正常,您应该看到ping回复进来。如果您无法再连接到beaglebone,请停用防火墙pfctl -d
并验证规则是否正确。如果您可以连接到beaglebone,但ping不成功,请验证路由表(beaglebone上的route
,mac pfctl -s nat
上的nat表,并确保运行{ {1}})。