1

Using RPi 3 model B with latest Raspbian Lite Jessie (4.9). RPi is connected to network via WiFi (192.168.0.5), and to a network printer via ethernet. I'm trying to make the printer available via WiFi, using it's built-in print server and not a USB-Cups-solution. Thus, I thought I was trying to bridge wlan0 and eth0, however, that seems to be impossible. So I'm trying to route instead, but without much luck – I can't even get WiFi and ethernet to be working at the same time. Printer is using a static IP (192.168.0.3), so no DHCP required. If possible, I would like to use the printer in the same subnet as everything else.

/etc/dhcpcd.conf:

...

interface eth0
    static ip_address=192.168.0.6/24
    static routers=192.168.0.1
    static domain_name_servers=192.168.0.1

/etc/sysctl.conf:

...

net.ipv4.ip_forward=1

...

Routing:

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE 

But as soon as I bring up eth0, wlan0 stops working. Pinging the router (192.168.0.1) brings up a Destination Host Unreachable, pinging the printer works; by changing the interface I can reach the router via ping -I wlan0 192.168.0.1. However, the RPi remains unreachable for any other device on the network.

  • 3
    It looks like you have the same IP network (192.168.0.0/24) on both eth0 and wlan interface, that will not work. – MatsK Aug 9 '17 at 11:58
1

Following the advice of MatsK, I configured different IP networks for eth0 and wlan0, and got it working. Here's how, using dhcpcd only (and not network manager).

Configure a static IP for your eth0 interface in /etc/dhcpcd.conf by adding to the end of the file:

interface eth0
    static ip_address=192.168.101.1/24
    static routers=192.168.101.1
    static domain_name_servers=192.168.101.1

Change routes by creating a dhcpcd-hook by creating the file /etc/dhcpcd.exit-hook:

/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -t nat -F
/sbin/iptables -A FORWARD -o wlan0 -i eth0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
/sbin/iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
/sbin/sysctl -w net.ipv4.ip_forward=1

Configure your default gateway (main router) to route traffic to 192.168.101.0 to your RPi, so it can forward it to eth0-connected devices. This depends on the brand and type of router you're using as your main gateway, it may have the possibility to set up custom routes.

If DHCP is needed on the eth0 side, install dnsmasq and change /etc/dnsmasq.conf to:

interface=eth0
no-dhcp-interface=wlan0
dhcp-range=interface:eth0,192.168.101.10,192.168.101.20,infinite

Else, manually configure static IPs on each device connected to eth0 of the RPi.

Bonus: Zeroconf can be forwarded (reflected) across all interfaces of the RPi by editing /etc/avahi/avahi-daemon.conf:

...
[server]
...
allow-interfaces=eth0,wlan0
...

[reflector]
enable-reflector=yes
...
  • nice that you got it up, and kudos for writing a answer to it. – MatsK Aug 11 '17 at 11:35
  • I have a similar situation, I want to use RPi3 wlan0 connect to home wifi network, and its eth0 connect to PC that has no wifi capability. I am able to setup DHCPCD and DNSMASQ to setup the bridge between wlan0 and eth0 port so the PC is able to connect to the internet via RPI3. However, because it is on a different subnet (eth0 is 192.168.0.x, wlan0 is 10.0.0.x), my other devices on the home wifi network is not able to talk to this PC behind the RPI3, what should I do to make it visible to other devices? – user97662 Jan 25 '18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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