I have a rule similar to this:

iptables -t nat -I PREROUTING -p tcp --dport 80 -s -j DNAT --to-destination

which redirects all http requests from 1.5 host to 1.2.. I want to make so it works only for one URL - to redirect only if user on 1.5 accesses google.com for example. Is it possible without using proxy?

2 Answers 2


By default, I would say it is not possible. BUT you can check if the --string option of iptables can help you

  • tried with string but it doesn't match anything Jun 26, 2012 at 9:54
  • I add like -m string --string 'google.com' it doesn't act like it is supposed to Jun 26, 2012 at 9:54

iptables/netfilter is a firewall and it is not designed to look at URLs, but you can try using string module if you want to look for specific string in the packet.

You can restrict the rule to specific IP addresses if that is applicable in your case and the web server rarely changes its name-IP mapping.

  • how can I set it for ip instead of google.com then? Jun 26, 2012 at 8:31
  • 1
    @Mr.BeatMasta: For cases like google.com, it will not be easy as google has several IPs and they are changing. You need to specify destination using -d option.
    – Khaled
    Jun 26, 2012 at 8:50
  • Yup exactly. Actually I've tried that, but it didn't work, though ip was not changed... could you provide an example for my case, please? maybe i've done sth wrong. Jun 26, 2012 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.