I have a BeagleBone Black connected directly to my desktop PC for development and testing. Occasionally, I need the BBB to connect to the internet, for example to download updated packages. This post describes how I am sharing the internet connection between the two computers.
I am making the following assumptions:
- eno1 is the name network interface that is connected to the internet
- enp12s0 is the name of the network interface on the BBB
- The subnet used is 192.168.123.0 / 255.255.255.0
Your configuration might be different, and you have to adjust the steps below accordingly.
First, enable the network interface that is connected to the BBB and and set its IP address:
# ip link set up dev net0
# ip addr add 192.168.123.1/24 dev enp12s0
Then enable packet forwarding:
# sysctl net.ipv4.ip_forward=1
To make the forwarding settings persistent, a sysctl configuration file must be created:
# nano /etc/sysctl.d/30-ipforward.conf
Now enable network address translation (NAT) on the interface that is connected to the internet:
# iptables -t nat -A POSTROUTING -o eno1 -j MASQUERADE
# iptables -A FORWARD -i enp12s0 -o eno1 -j ACCEPT
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
The host PC will now forward relevant traffic from the BBB to the internet.
Configure the BBB
Configure a static IP address and route:
# ip addr add 192.168.123.100/24 dev eth0
# ip link set up dev eth0
# ip route add default via 192.168.123.1 dev eth0
Then configure any DNS servers, if needed (I use Google’s):
# nano /etc/resolv.conf
The BeagleBone Black should now be able to access the internet.