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. But you need to make sure the connected hosts don't use some public DNS like 1.1.1.1
, instead must use DNS provided by DHCP i.e. IP address of Android device.
Create file /system/etc/dnsmasq.conf
and add the following option:
address=/#/192.168.43.1
See details in manpage. Start hotspot and test. Similarly you can use other DNS servers on your Android device e.g. dnscrypt-proxy.
NOTE:
For http://example.com
request goes to 192.168.43.1:80
and for https://example.com
it goes to 192.168.43.1:443
. However if you type http://example.com/test.html
it requests page 192.168.43.1:80/test.html
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:
192.168.43.1:8080 *
?
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 (192.168.43.1
) not ports (:8080
). You have to mention the port on web browser. See below links for details on DNS.
RELATED: