Ubuntu – Client isolation in Ubuntu with hostapd

12.04hostapdiptableswireless

We have created a wifi hotspot or a wireless access point using hostapd in Ubuntu. How can we isolate wifi clients the same way "Client Isolation" does in some access points? Is there any way we can combine iptables with hostapd to apply some firewall rules between wifi clients?

Best Answer

Create an iptables rule on input and output that allows the source address range to talk to the router/default gateway, additional rules for any servers or other resources on that subnet.

Create a final rule that drops packets between the source address range and the source address range.

iptables -A INPUT -i $WIFI -o $WIFI -s 192.168.1.0/24 -d 192.168.1.1 -j ACCEPT
iptables -A INPUT -i $WIFI -o $WIFI -s 192.168.1.0/24 -d $SOMESERVERIP -j ACCEPT
iptables -A INPUT -i $WIFI -o $WIFI -s 192.168.1.0/24 -d $SOMEOTHERSERVERIP -j ACCEPT
iptables -A INPUT -i $WIFI -o $WIFI -s 192.168.1.0/24 -d 192.168.1.0/24 -j DROP

The basics of this chain of events is:

  1. if it's in the subnet and it's talking to the gateway, accept it
  2. If it's in the subnet and it's talking to a server, accept it
  3. Rule 2 repeats until you run out of acceptable servers
  4. If it's in the subnet and it's talking to anything else in the subnet, drop it
Related Question