1

I have the following situation

enter image description here

I would like to make the Internet connection on wlan0 of the Pi available to all devices connected on eth0. I'am using Raspian Stretch, predictable network interface names disabled, /etc/network/interfaces is empty, ip4 forwarding enabled, /etc/dhcpcd untouched.

The Pi receives the eth0 config from the LAN side DHCP Server and the wlan0 config from the AP "Router".

Following several tutorials here and elsewhere routing traffic from eth0 to wlan0 should be straightforward. See, for example, this post eth0 to wlan0 NAT router setup?, this one eth0 to wlan0 NAT router [duplicate] or this Cent OS based solution CentOS / Redhat Linux Internet Connection Sharing.
Definitions:

  • SSID1: Subnet 192.168.1.0/24 GW: 192.168.1.1 (on Router in Image)
  • SSID2: Subnet 192.168.2.0/24 GW: 192.168.2.1 (on PI:eth0)
  • Host1: on Subnet 192.168.1.0/24 GW: 192.168.1.1 (on Router in image)

Unfortunately, none of those solutions which are basically all the same seem to work in the case abvove.

Core step is route traffic from eth0 to wlan0 using iptables

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

I am able to do this:

  • ping or access Host1 from 192.168.2.0/24 by webbrowser

I am not able to access any host on the internet from 192.168.2.0/24 or from the Pi itself

Looks like a gateway or a route is missing? The result of ip route

$ip route
default via 192.168.2.1 dev eth0 src 192.168.2.1 metric 202
default via 192.168.43.1 dev wlan0 src 192.168.43.100 metric 303
192.168.2.0/24 dev eth0 proto kernel scope link src 192.168.2.1 metric 202
192.168.43.0/24 dev wlan0 proto kernel scope link src 192.168.43.100 metric 303

Now I am at an end with my knowledge, what is missing and what should/could I do? Any help would be appreciated.

8
  • In your picture the ip address 192.168.2.1 is the same then GW=192.168.2.1. This isn't possible. What is AP "Router"? What subnet has wifi with ssid "SSID1"? What subnet has wifi with ssid "SSID2"? To what subnet belongs Host1? To what subnet belongs Test1? Please edit your question to update it.
    – Ingo
    Commented Aug 17, 2018 at 13:43
  • What is the output of ip route on the Pi? Commented Aug 17, 2018 at 14:08
  • As has already been pointed out, and it case it was not clear enough, both networks set up "around" the wlan router are the same (192.168.2/24, I presume). Set it up so that you don't have duplicate network segments on any of the 3 networks shown there (SSID1, SSID2, pi to WLAN Router) and everything should start working fine.
    – eftshift0
    Commented Aug 17, 2018 at 18:03
  • My intention ist have only one Subnet on the right hand side of the Pi, ie. 192.168.2.0/24. The fact that there is another WLAN with SSID "SSID2" should be irrelevant. I can switch off "SSID2", connect all client through cable and have the same result.
    – bscwuenn
    Commented Aug 18, 2018 at 6:16
  • The problem is not the name of the wireless networks. It's that the WLAN ROUTER has two overlapping network segments set up (both segments are 192.168.2.0/24). Take one of the segments and set it to 192.168.3.0/24, for example). Also, I see another problem with the pi set up It's displaying two "default" GW. That can't be good (and will probably make it misbehave) so this line should be gone default via 192.168.2.1 dev eth0 src 192.168.2.1 metric 202.
    – eftshift0
    Commented Aug 18, 2018 at 9:13

1 Answer 1

1

I have been able to solve this problem withe the help of the comments. First i have disabled the wlan "SSID2". So the eth0 interface of the pi faces exactly one subnet 129.168.2.0/24. Alle devices are connectet using cables and a switch with dhcp cababilities. The output of

> ip route  

showed a default route for eth0 (added automatically by dhcpdcd)
Using

Sudo ip route del 0/0 dev eth0  

got rid of that entry and as soon as i enabled routing by

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

the system worked as desired. Case closed, Thank you.

1
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Commented Apr 1, 2020 at 10:03

Your Answer

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

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