Android - How to set up a host to IP mapping on unrooted Android?
You cannot simply edit the hosts file on Android, as it resides on a read-only file system: /system/etc/hosts
, see:
- How to edit etc/hosts file
- How to change the hosts file on android
Alternatives are:
- use a DNS server like DNSMasq in your local network to take care for that "centrally"
- use "root powers" to force-edit the system file as described above
- install a "local DNS server" on your Android device to use that, e.g. DNS Server
As mentioned by lzzy, you can use DNSMasq server to achieve this. But Chrome uses own DNS resolving process and this method may not work.
To start the server use the following command:
sudo /usr/local/sbin/dnsmasq -d \
--no-hosts \
--no-resolv \
--conf-file=/dev/null \
--server=8.8.8.8 --server=8.8.4.4 \
--address=/example.com/192.168.0.101
sudo
required to bind on port 53-d
start server on foreground--no-hosts
do not use local hosts file--conf-file=/dev/null
do not use any config file--server=8.8.8.8 --server=8.8.4.4
addresses of upstream servers (Google DNS in this example)--address=/example.com/192.168.0.101
hosts to override. You need to add your hosts at this line. You can also add multiple hosts there.
Then change DNS server on the device. This can be easily done using the DNS Changer app.
After these steps, the requests to these hosts should be sent to your addresses.