0

It's been more than 1 week am trying to configure my Pi as an internet gateway. I've played with several 10s of configurations shown on the web, but none of them work.

here's my setup: hard: a Pi with an external USB <---> ethernet device soft: Raspbian scratch with hostapd and dnsmasq running

I've disabled DHCP and wifi of my adsl modem.

here's what i want to achieve: eth0: the pi's onboard ethernet. it will be connected to a hub and serve as a DHCP server to my local wired network.

eth1: only the USB<--->eth is connected to my modem. i want it to be the only link of my whole ( wired and wireless ) local network with the outside world thru my adsl modem.

wlan0: will be the wifi access-point of my local network.

all 3 devices own their IP configured as static in the /etc/networks/interfaces file. here's the file:

auto eth1

iface eth1 inet static

   address 192.168.1.1

   netmask 255.255.255.0

   gateway 192.168.1.254

   dns-nameservers 192.168.1.254

   metric 200

auto eth0

iface eth0 inet static

   address 192.168.0.254

   netmask 255.255.255.0

   metric 202

auto lo

   iface lo inet loopback


auto wlan0

iface wlan0 inet static

   address 192.168.0.253

   netmask 255.255.255.0

   metric 201

EOF ------------------------

the dnsmasq DHCP server gives IPs to local wired and wireless devices. it is setup like this in /etc/dnsmasq.conf:

interface=eth0                  # Use interface eth0

   listen-address=192.168.0.254 # Explicitly specify the address to listen on

   bind-interfaces              # Bind to the interface to make sure we aren't sending things elsewhere

   server=192.168.0.254         # Forward DNS requests to Google DNS

   domain-needed                # Don't forward short names

   bogus-priv                   # Never forward addresses in the non-routed address spaces.

   dhcp-range=eth0,192.168.0.1,192.168.0.100,255.255.255.0,12h






interface=wlan0                  # Use interface wlan0

   listen-address=192.168.0.253 # Explicitly specify the address to listen on

   bind-interfaces              # Bind to the interface to make sure we aren't sending things elsewhere

   server=192.168.0.254         # Forward DNS requests to Google DNS

   domain-needed                # Don't forward short names

   bogus-priv                   # Never forward addresses in the non-routed address spaces.

   dhcp-range=eth0,192.168.0.101,192.168.0.200,255.255.255.0,12h

tho you can se all of them, here's my static IPs:

*my modem: static ip 192.168.1.254

*eth0: static ip 192.168.0.254

*eth1: static ip 192.168.1.1 ( as it's connected to my modem )

*wlan0: static ip 192.168.0.253

I also configured routing thru iptables with those commands:

# Allow traffic initiated from LAN to access "the world"
iptables -I FORWARD -i eth0 -o eth1 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT

iptables -I FORWARD -i wlan0 -o eth1 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT

# Allow established traffic to pass back and forth
iptables -I FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

# Masquerade traffic from LAN to "the world"
iptables -t nat -I POSTROUTING -o eth1 -s 192.168.0.0/24 -j MASQUERADE

what i get is really weird ! eth0<---->eth1 routing works like a charm ! OR wlan0<--->eth1 routing works like a charm as well !

but i've been totally unable to make both work at the same time.

anybody got an idea ? I'd like to redo a whole setup as i guess i messed around many things and am now sure of nothing ( interfaces setup, dnsmasq config, hostapd config, etc.... )

as a crappy solution i think i gonna setup 2 PIs: one as eth0<--->eth1 gateway and a second one, connected to my local network hub, used as a wifi access-point. I really hate this solution but i got no other one and i confess that after hours of try and redo am somewhat bored and fed-up :-(

I also posted questions on other forums with no answer.

0

You are using the same 192.168.0.0/24 subnet for both eth0 and wlan0. From your description, it sounds like you want to route between all 3 interfaces, which means that eth0 and wlan0 need to be separate subnets with corresponding iptables rules for each.

If you truly want eth0 and wlan0 to share the same subnet, you need to bridge eth0 and wlan0, which can work but is not generally recommended. You'd then use the bridge interface (e.g. br0) in your iptables rules.

For all of that, the RPi is a pretty dicey router. Performance issues aside, just having those easily dislodged USB power and network adapters laying about is asking for headaches. Wifi performance is "not great".

  • okay i guess i missed subnet constraints. i thought that was possible and i think my problem resides here. lemme dig a bit that way and post back here if i got it working, or not. For bridge ( i made one called br0 ) it works like a charm but seems to block my ssh link ( RPi as a server and windows as a client ). therefore it's a no-go for (from a now-deleted answer of the OP) – Ghanima Aug 15 at 7:27
0

First of all, i think bobstro is right with his answer. You can test it easily, just disable one of the devices eth0 or wlan0.

When testing only wifi try the following rules:

iptables –t nat –A POSTROUTING –o eth0 -j MASQUERADE
iptables –A FORWARD –i wlan0 –o eth0 -j ACCEPT
iptables –A FORWARD –i eth0 -o wlan0 –m state --state RELATED,ESTABLISHED –j ACCEPT 

And dont forget to enable routing:

echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward 

Tell Linux to remember this change:

sudo nano /etc/sysctl.conf 

and uncomment or write this line:

net.ipv4.ip_forward=1
  • wlan <--> eth1 works like a charm with masquerading when eth0 is down. The mess comes when both eth0 and wlan0 are up and talking with wlan0. yes IPV4 forwarding is operative. (from a now-deleted answer of the OP) – Ghanima Aug 15 at 7:27

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.