I'm trying to setup a captive portal (catch-all HTTP server) on a Pi. I have configured the Edimax USB adapter with DHCPD and hostapd and that works perfectly. Client devices can connect and access the Pi's IP in their browser and load the target page. My goal is to get dnsmasq to direct all requests to the target landing page (

The following is my configuration: /etc/network/interfaces

auto lo

iface lo inet loopback
# auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet static



With the above configuration, pings to external domains and IP addresses still resolve to external networks whereas a replica of the above configuration on my local ubuntu 14.04 workstation redirect to as expected. It appears the Pi is failing to route DNS via dnsmasq despite restarts, reloads, etc. Any suggestions, please?

2 Answers 2


I solved this problem using IPTABLES with this rule:

sudo iptables -t nat -A PREROUTING -d 0/0 -p tcp --dport 80 -j DNAT --to-destination

You will need to install iptables-persistent to keep this rule after reboot/shutdown.

p.s: I found a lot of answers on the internet saying that with just one line in the /etc/dnsmasq.conf we can solve this:


Unfortunately, it didn't work for me.

Raspberry pi 3, Raspbian GNU/Linux 8.0 (jessie), hostapd v2.3, dnsmasq, EDIMAX RTL8188CUSv2.76


Is it possible that the DHCP DNS server configuration varies between your Ubuntu and RPi dnsmasq configurations? Have you confirmed the DNS settings on the client machines?

This highlights one possible shortcoming of your approach: It will only work for clients that play along by using your DNS server settings. Bypassing it by using an external DNS server is trivial. If you are concerned about this, and the RPi is to be your router, you might try redirecting web traffic using iptables instead.

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.