-1

I'm trying to redirect a host to a specific link on my network when they try to browse through HTTP.

The IP address of the host I'm trying to redirect is 192.168.2.19 and my web-server is on 192.168.2.15:6969/test.js. When I redirect the user I can only get him to 192.168.2.15:6969 and not the relative path. I tried specifying in the iptables command but it did not work.

Here's what I did:

echo 1 > /proc/sys/net/ipv4/ip_forward 
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000
iptables -t nat -A POSTROUTING -j MASQUERADE 
iptables -t nat -A PREROUTING -s 192.168.2.19 -p tcp --dport 80 -j DNAT 
--to-destination 192.168.2.15:3000/test.js
techraf
  • 4,163
  • 8
  • 27
  • 44
Katz
  • 101
  • 3

1 Answers1

4

You cannot do this with iptables. You're trying to perform an HTTP redirect, so you'll need to perform the redirect using an application that speaks HTTP, like apache or nginx.

EEAA
  • 108,414
  • 18
  • 172
  • 242