Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a rule similar to this:

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

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?

share|improve this question

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

share|improve this answer
    
tried with string but it doesn't match anything –  Mr. BeatMasta Jun 26 '12 at 9:54
    
I add like -m string --string 'google.com' it doesn't act like it is supposed to –  Mr. BeatMasta Jun 26 '12 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.

share|improve this answer
    
how can I set it for ip instead of google.com then? –  Mr. BeatMasta Jun 26 '12 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 '12 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. –  Mr. BeatMasta Jun 26 '12 at 9:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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