mushu999
Posts: 29
Joined: Sun Aug 20, 2017 11:24 pm

frustrated: how to create backwards router on 3B+ ??

Thu Nov 22, 2018 10:46 pm

So I say "backwards" because all the googling I've found shows several completely different ways to turn the Pi 3B+ into a bridge or router by using a wired connection to the Internet and allowing wireless clients to connect to it.

I want it the other way around. And since you're asking yourself "why?" it is because I need a wired ethernet client hardware to be assigned an IP address in the garage from the Pi which is itself getting an IP address via wireless to a router in the house, and I don't want to lay 100 feet of CAT6 from the living room into the garage just to connect that hardware (which *would* work.)

So I'm at the point where, via iptables rules and installing hostapd (which I've subsequently removed because I think that isn't what I want) I no longer have access to the network via wireless. When it boots it says near the end "my IP address is 192.168.2.1" but that is the one assigned to the eth0 for the other hardware to plug in to, so I don't want the Pi itself to have that IP addr. One more thing: I was having errors at bootup with an "rc.local Compatibility" issue so I grep'd dmesg for dhcp and found two versions of dhcp installed so I removed dhcp5 and the error went away.

Here's some output, which sucks because no connection, so all typed manually:

iwconfig:

Code: Select all

eth0    no wireless extensions
lo        no wireless extensions
wlan0  IEEE 802.11 ESSID: off/any
           Mode: managed Access Point: not associated  Tx-Power=31 dBm
           Retry short limit: 7  RTS thr:off  Fragment thr: off
           Power management: on

ifconfig:

Code: Select all

eth0:  flags=4099<up,broadcast,multicast> mtu 1500
          inet 192.168.2.1  netmask 255.255.255.0  broadcast 192.168.2.255
no packets or errors
...
lo:      flags=73<up,loopback,running> mtu 65536
...
wlan0: flags=4099<up,broadcast,multicast> mtu 1500
no packets or errors

/etc/dhcpcd.conf (only the lines not commented out):

Code: Select all

hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, hostname
option classless_static_routes
option ntp_servers
option interface_mtu
require dhcp_server_identifier
slaac private
interface wlan0
static ip_address=192.168.1.13/24

(for next item note that /etc/network/interfaces.d/ contains no files)
/etc/network/interfaces:

Code: Select all

source-directory /etc/network/interfaces.d
auto lo
auto wlan0
iface lo inet loopback
iface wlan0 inet dhcp
allow-hotplug eth0
iface eth0 inet static
   address 192.168.2.1
   netmask 255.255.255.0
   post-up iw dev $IFACE set power_save off
post-up iptables-restore < /etc/iptables.ipv4.nat

/etc/iptables.ipv4.nat:

Code: Select all

*filter
:INPUT ACCEPT [105:8608]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [49:5764]
-A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -j ACCEPT
COMMIT
*nat
:PREROUTING ACCEPT [10:1002]
:INPUT ACCEPT [10:1002]
:OUTPUT ACCEPT [2:212]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o wlan0 -j MASQUERADE
COMMIT

/etc/wpa_supplicant/wpa_supplicant.conf:

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=US
network={
  ssid="my-router-id"
  psk="the-password"
}

I may have typo'd so let me know if something looks wonky. Also if you need other file data let me know. I understand this is difficult to troubleshoot via proxy but I'm hoping someone has at least an idea I can try. Thanks in advance and Happy Thanksgiving!

TL;DR: how do I get rpi 3B+ to assign IP on eth0 but receive IP on wlan0?
Last edited by mushu999 on Fri Nov 23, 2018 2:38 pm, edited 2 times in total.

epoch1970
Posts: 3871
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: frustrated: how to create backwards router on 3B+ ??

Fri Nov 23, 2018 8:11 am

Is this backwards enough?

Common ways to avoid this grief:
- Use 2 networks, one for wifi, one for ethernet, and route/masquerade between the 2 networks. Not transparent, but works in practice.
- Get a "gaming adapter" or "wifi travel router" that features an ethernet port and wifi capability. In general these will allow to connect over wifi uplink a single machine connected via ethernet. Works only for a single machine and direct connection, not when connected to a network segment via a switch.
- Find network hardware that will handle bridging over wireless. Not standards-compliant, so your best bet is getting 2 router/AP units of the same brand or at least running the same software.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

mushu999
Posts: 29
Joined: Sun Aug 20, 2017 11:24 pm

Re: frustrated: how to create backwards router on 3B+ ??

Fri Nov 23, 2018 2:33 pm

OMG thank you! That's exactly what I'm trying to do. Will get on it right away. :-)

epoch1970
Posts: 3871
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: frustrated: how to create backwards router on 3B+ ??

Fri Nov 23, 2018 4:21 pm

Also here, you can follow the tribulations of someone trying to apply the above guide.
A bit lengthy but could contain additional useful bits of info. The OP used 2 Pis, and a Pi3b+ on the "house" side.
HTH
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

mushu999
Posts: 29
Joined: Sun Aug 20, 2017 11:24 pm

Re: frustrated: how to create backwards router on 3B+ ??

Sun Dec 16, 2018 12:00 am

Okay, I followed several guides and with a mishmash of configs I managed to get the pi to act as a router for the ethernet port over wifi. It actually works, since I disabled my laptop's wireless and plugged in an ethernet-to-usb adapter, then plugged it in the pi and got an IP address and had Internet connectivity, yay!

However, whenever the ethernet is plugged in to the pi, the pi itself no longer has Internet connectivity. Would really like someone to point me in the right direction, I think it's an iptables issue. Here is what is set up now on the pi:

Code: Select all

$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target        prot   opt  source                 destination

Chain FORWARD (policy ACCEPT)
target        prot   opt  source                 destination
ACCEPT        all    --   anywhere               anywhere             state RELATED,ESTABLISHED
ACCEPT        all    --   anywhere               anywhere

Chain OUTPUT (policy ACCEPT)
target        prot   opt  source                 destination

So what is missing to allow the pi to also access the Internet when ethernet is plugged in?

Thanks in advance!

Return to “Advanced users”