1

I have two wlan interfaces: wlan0 wlan1.

wlan0 is an AP managed by hostapd, where as wlan1 is a normal wifi interface, which is connected to my home router via wpa_supplicant. Additionally I have my eth0 interface, which is also connected to my router. I want to build up a wifi repeater for the pi.

I have the following iptables rules

AP_INTERFACE="wlan0" # ap
SOURCE_INTERFACE="wlan1" # to router

# Flush rules
iptables -t nat -F
iptables -F

# Apply new rules
iptables -t nat -A POSTROUTING -o $SOURCE_INTERFACE -j MASQUERADE
iptables -A FORWARD -i $SOURCE_INTERFACE -o $AP_INTERFACE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $AP_INTERFACE -j ACCEPT

# Save rules
iptables-save > /etc/iptables/rules.v4 # iptables-persistent

If I use this script to set my iptables rules, the clients connected to the AP cannot access anything else than the Pi itself, because the packets are not forwarded. If I changed the SORUCE_INTERFACE to eth0 it works for unknown reasons.

/etc/network/interfaces:

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan1
iface wlan1 inet manual
  wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan0
iface wlan0 inet static
  address 10.10.11.1
  netmask 255.255.255.0

route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.10.10.1      0.0.0.0         UG    202    0        0 eth0
0.0.0.0         10.10.10.1      0.0.0.0         UG    304    0        0 wlan1
10.10.10.0      0.0.0.0         255.255.255.0   U     202    0        0 eth0
10.10.10.0      0.0.0.0         255.255.255.0   U     304    0        0 wlan1
10.10.11.0      0.0.0.0         255.255.255.0   U     0      0        0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U     303    0        0 wlan0
  • This may be the default route. Run route -n to display the routing table. – Anonymous Aug 18 '17 at 14:52
  • I added the route -n output to the post. – Scrumplex Aug 18 '17 at 15:05
  • So you have two default routes to Internet (0.0.0.0) but eth0 has priority, having the lowest metric. At this point you could try: (sudo) route del -net 0.0.0.0 gw 10.10.10.1 netmask 0.0.0.0 dev eth0 and test again. NB: untested but should work. – Anonymous Aug 18 '17 at 15:19
  • That actually fixed it! Can I instead of deleting just change the priority of the route? Changing the priority would be the solution. (Edit your answer) – Scrumplex Aug 18 '17 at 15:21
  • I see several options from now: one option would be to set fixed metrics in your interfaces file (see: unix.stackexchange.com/questions/292940/…. Another option would be tweaking your DHCP settings to discard that secondary route on eth0 (See: raspberrypi.org/forums/viewtopic.php?f=66&t=90469) – Anonymous Aug 18 '17 at 17:33

Your Answer

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

Browse other questions tagged or ask your own question.