I literally have the same question as found in this post: How to redirect complete outgoing phone's traffic to a proxy server?

I have an Android phone acting as a hotspot server (using KWS). I am able to connect another device and access my little webpage by typing into the URL search of my browser, so no problem there.

However, I would like for all requests by connected devices to be redirected to my webpage.

The answer in the linked question suggests running two DNS servers using the Server's Ultimate app. My only hesitation is that it is not free, and the 'free' version is a 7 day trial. I have tried another app called "Set DNS," which seems promising, but it will not recognize my hotspot as a network; it keeps waiting for me to connect to something.


  • Can I simply change the /system/etc/hosts file as mentioned in the linked post?
  • Would I add a line such as: *?
  • If not, must I purchase Server's Ultimate, or is there another alternative?

PS: This is for an advertisement. The webpage is to be static and informative (no malicious activity).


NOTE: Solution suggested here requires root access.

I would like for all requests by connected devices to be redirected to my webpage

When you create hotspot, Android runs dnsmasq as DHCP/DNS server (up to Android 9). We can use this DNS server to resolve every domain to your desired IP address. Create file /system/etc/dnsmasq.conf and add the following option:


See details in manpage. Start hotspot and test. Similarly you can use other DNS servers on your Android device e.g. dnscrypt-proxy.

You need to make sure that the connected hosts don't use some public DNS like, instead must use DNS provided by DHCP i.e. IP address of Android device. Or redirect all DNS traffic to local DNS server:

~# iptables -t nat -I PREROUTING -p UDP --dport 53 -j REDIRECT --to 53


For http://example.com request goes to and for https://example.com it goes to However if you type http://example.com/test.html it requests page which should exist, otherwise an error will be returned. An easy way is to configure your advertisement webpage as index page and default error page. For instance index-file.names and server.error-handler options on lighttpd.

  • Can I simply change the /system/etc/hosts file as mentioned in the linked post?
  • Would I add a line such as: *?

hosts file is used by DNS resolvers which are usually part of main C library of OS. As far as I know the built-in resolvers on Android/Linux/Windows don't support wildcards, so the * trick won't work. Secondly, domain names are resolved to IP address ( not ports (:8080). See below links for details on DNS.

Web browsers by default use port 80 for http requests. If you are running server on some other port, you have to mention the port on web browser. Or redirect all newly generated TCP traffic from port 80 to 8080:

~# iptables -t nat -I PREROUTING -m conntrack ! --ctstate RELATED,ESTABLISHED -p tcp --dport 80 -j REDIRECT --to 8080



I made an app uses similar solution mentioned by irfan. It has very minimal UI and requires root permission. Check here: https://forum.xda-developers.com/android/general/guide-setup-fake-captive-portal-android-t4011689

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.