How do I share my mac's internet connection with my beaglebone black?

I've read a lot of answers for this one, but none of them worked (presumably because they were written for outdated OS X versions). How do I actually share my Mac's internet connection with the beaglebone?


Solution 1:

I will assume that you have successfully installed the necessary drivers and the beaglebone shows up in your list of network interfaces. Once that is the case, make sure you have properly configured the IP address and netmask. For the default beaglebone connection this looks something like this: networking setup

Once that is done, verify that you can connect to the beaglebone:

mac$ ssh [email protected]
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:~#

You are now ready to setup the nat, to allow the beaglebone to share your network connection. For that, first find the name of the network interface that's associated with your 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

Then, activate ip forwarding and set the appropriate firewall rule:

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

Naturally, you need to substitute en9 for the interface name you found in the previous step. Also, if you already have the firewall enabled, you'll want to manually add that to the firewall configuration.

Lastly, we need to set up the default gateway:

mac$ ssh [email protected]
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

If everything worked, you should see the ping replies come in. If you can't connect to the beaglebone anymore, deactivate the firewall pfctl -d and verify that the rule was correct. If you can connect to the beaglebone, but the ping doesn't succeed, verify the routing table (route on the beaglebone, the nat table on the mac pfctl -s nat, and make sure that you ran the sysctl).