0

I want to redirect all port 80 traffic (regardless of the domain name) to go to a specific external website. Therefore, if the user enters "www.google.com" or anything, it sends them to "www.mysite.com" Bonus points if it also works with IP addresses (hence iptables) in addition to host/domain names.

I've tried the "address" setting in dnsmasq.conf as well as playing with IPTABLES to no avail. The OS is Raspbian Buster Lite.

Here is my dnsmasq.conf file:

domain-needed
interface=wlan0
dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,1h
address=/#/10.3.141.1
except-interface=lo
except-interface=eth0
R OMS
  • 101
  • 1
  • 1
    I'm not near my PC ATM, but an iptables rule like "iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 1.2.3.4" should work. Note that 1.2.3.4 needs to answer correctly regardless of the domain name that's presented. – davidgo Nov 01 '19 at 08:45
  • I don't think there is a PREROUTING chain on Raspbian Buster Lite. At least last time I listed the rules, it wasn't present. – R OMS Nov 03 '19 at 23:45

1 Answers1

0

iptables can't redirect to a website as it doesn't use URLs like that. You're confusing layer 3 traffic with layer 7 in the OSI stack.

See this post for details on why this can't work (and a look at somebody else that already asked this question).

You can't do this with iptables. You're confusing layers in the networking stack: IP is layer 3 in the OSI model, HTTP is layer 7. See http://en.wikipedia.org/wiki/OSI_model

If you want to redirect URL requests you could use Apache together with mod_proxy.

CubeSyVal
  • 31
  • 3
  • This is incorrect. – davidgo Nov 01 '19 at 08:40
  • I'm not confusing the two. My problem has two parts. One is redirecting DNS for users who enter domain names into their browser. The second is redirecting user who enter IP addresses in the browser. Now that I've clarified my requirement, do you still think iptables wouldn't work? – R OMS Nov 01 '19 at 20:15