Ubuntu: Redirect iptables to apache without internet connection



Question:

I have set up a Personal hotspot using Hostapd. But this hotspot is not connected to the internet but I do have Apache installed on it. What I am trying to achieve is to redirect all the clients (that are connected to my hotspot) to my apache page when they visit another website. So basically redirect all traffic to my Apache page.

What I have tried is :

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.150.1:80  

But with this iptable the clients only get redirected to my Apache webpage when I share an internet connection with my hotspot. But without the internet connection they do not get redirected.

Also tried:

sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 192.168.150.1:80  


Solution:1

Impressive as it was not established where the traffic comes.

-s IP  -i Interface  

Examples:

sudo iptables -t nat -A PREROUTING -s 192.168.150.1 -p tcp --dport 80 -j DNAT --to-destination 192.168.150.1:80    sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j DNAT --to-destination 192.168.150.1:80  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »