2

My Main Question

How do I configure my RPi so that I can share its internet connection with an IoT device plugged in via ethernet cable in addition to sharing its internet connection via its wifi-adapter?

My Setup

I have multiple IoT devices that need internet access. Most are wireless, but one requires a wired ethernet connection. I have an RPi running Raspbian stretch with a static IP issued by my organization's network admin. The connection to my org network is via ethernet cable, and uses the built-in ethernet port on the RPi. It is eth0 in my configuration. The RPi itself has no trouble connecting to the internet.

I was able to configure the RPi as a wireless access point using this tutorial. That works great. My wireless IoT devices can connect to the wifi network on my RPi without issue.

For the wired device, I purchased a USB ethernet adapter that shows up as eth1.

I'm trying to setup eth1 so that any device that is plugged into it will automatically be given an IP address and have access to the internet.

Here are the current contents of key files (or ones that appear to be "key files" to me):

# /etc/network/interfaces
source-directory /etc/network/interfaces.d
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0
# /etc/dhcpcd.conf
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private
nohook lookup-hostname

# RaspAP-WebGui wireless configuration
interface wlan0
static ip_address=10.3.141.1/24
static routers=10.3.141.1
static domain_name_server=1.1.1.1 8.8.8.8
# /etc/rc.local
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP Address is %s\n" "$_IP"
fi
iptables-restore < /etc/iptables.ipv4.nat
echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP
iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP
exit 0
# /etc/iptables.ipv4.nat
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT

What I've Tried

I'm a web developer and don't have enough background in networking to have more than a bare grasp of what I'm trying to do. Essentially what I believe is that I need to setup eth1 to act as a DHCP server for anything that connects to it, and then allow it to bridge to my internet connection which comes in via eth0. I tried to mimic the settings for wlan0 with eth1.

Of course, I've done a lot of googling, but I never fully feel like I understand the reasoning behind the various configurations I've been reading, and therefore am not sure what I should try next.

I tried adding eth1 to the br0 bridge by adding bridge_ports eth0 eth1 to /etc/network/interfaces.

I tried assigning different static IP addresses to eth1 in /etc/dhcpcd.conf. Here are the addresses that I've tried (both with and without having it be a part of the bridge):

# first try
interface eth1
static ip_address=10.4.141.1/24
static routers=10.4.141.1
static domain_name_server=1.1.1.1 8.8.8.8

# second try
interface eth1
static ip_address=10.3.141.2/24
static routers=10.3.141.2
static domain_name_server=1.1.1.1 8.8.8.8

# third try
interface eth1
static ip_address=192.168.2.3/24
static routers=192.168.2.3
static domain_name_server=1.1.1.1 8.8.8.8

I was successful at getting eth1 to assign an IP address (in the host org network's IP address range) to a computer that I connected to it, but I haven't yet been able to also get internet access through that connection. Not only that, usually when I do this, though, my RPi loses internet access altogether, but not immediately. It will have internet access for a few seconds/minutes when it first boots up, but then loses it.

It feels like I'm really close, but I'm missing some key piece of understanding about how this stuff works.

Thank you for your time!!!

2
  • With the current config the wlan0 interface is bridged with the eth0 interface and devices on wlan0 get their ip address from the DHCP server on the organization's network, isn't it? Can you confirm this?
    – Ingo
    Sep 9, 2019 at 18:53
  • Oh! Yes, I suppose so. The IP address of devices connected to wlan0 is within the organization's IP range, so that must be true.
    – morphatic
    Sep 9, 2019 at 19:25

1 Answer 1

2

As noted in a comment, devices connected to the access point (wlan0) get an ip address from the subnet of the organization's network. This is given by the bridge br0 with member interfaces wlan0 and eth0. It also implies that there is a DHCP server running on the organization's network that serves the devices connected to the bridge. Currently this are only devices connected to the access point. This also means there is no need for a second DHCP server that serves devices on eth1. Just adding interface eth1 to the bridge as third member interface should do the job. Then it will also become member of the broadcast domain (subnet) from the organization's network like wlan0. So far in theory.

Since years I haven't used old style networking you have configured so my practical knowledge is limited with it and I don't have a test environment for it. You have to add eth1 to the bridge as member the same way you did with wlan0 and eth0. As far as I can see you only have to modify in /etc/network/interfaces the line:

bridge_ports eth0 wlan0
# to
bridge_ports eth0 eth1 wlan0
1
  • It worked!!! So simple, and I was so close. I had tried to bridge eth0 to eth1 on a separate line rather than putting all three interfaces on the same line. Thank you so much!
    – morphatic
    Sep 11, 2019 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.