I'm working on a personal project, but I just can't get a part of it to work.
My goal is that on an android device, certain domains will be redirected to a custom webpage. It would be a very basic blocking / blacklist system for websites, but for this project I need to deliver my own custom error webpage. It doesn't have to be 100% unhackable and foolproof but I want it to work 90% of the time. I can make it stronger later, I just want to crack this first part.
First I looked into setting up a custom DNS lookup using DNSmasq. However this hasn't worked out, mainly because I don't have the hardware to run it.
So the next thing I'm trying is to edit the hosts file on the android device, so that certain domains names get resolved to the IP I have set up. I've got that working ok so the domain names resolve correctly. But where to resolve them to?
- I've got a unique IP set up on subdomain on my shared web hosting. This doesn't seem to work because the IP doesn't deliver the web content, instead it redirects it to the domain name. I've got an open ticket to see if this can be changed.
- I'm trying to see if I can host a webpage on the same android device so that visiting 127.0.0.1 will respond with the webpage. I have tried various webserver apps, but none (so far) will allow hosting on port 80 which is the default web port, and I can't enter ports into the hosts file.
- If I can't get that to work, next thing to try is to get a raspberry pi (out of stock everywhere) or a more expensive mini pc, and run a webserver on a static local ip. (Only needs to work on local network)
Right now I'm working on the second point, so main question is, how can I host a webpage on the localhost of an android device itself? So that visiting 127.0.0.1 on my android device will show up my custom webpage?
CodePudding user response:
Run this command on your android:
iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port YOUR_SERVER_PORT
It will redirect your requests for port 80 to another port.