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

I'm on a simple linux proxy. I'd like to add iptable rules to drop all requests for a specific domain. I figured I run a dig command to get the ip addresses for the domain and then add an iptable rule for each one. It seems, however, that it doesn't work to bind to more than one ip address. So, it seems I need to add ip ranges like this...

iptables -I FORWARD -p tcp -m iprange --dst-range 66.220.144.0-66.220.159.255 --dport 443 -j DROP

That seems to work. However, it has proven pretty problematic to parse the output of dig and correctly create the appropriate iptable rules. Is there a better way?

share|improve this question
    
A better solution would be to work with the DNS requests. Either run a DNS proxy and filter the domain out, or do an iptables text match on the DNS queries and reject those packets. –  Patrick Jun 9 '12 at 7:33
    
Thanks for your comment! In this instance I don't think DNS will work because we only want it to apply to port 443 traffic not port 80 traffic. As I understand it there is no way in a DNS request to distinguish between the two. –  user548971 Jun 9 '12 at 17:07

1 Answer 1

You can specify hostnames in iptables commands which will get resolved at rule-add time. Hostnames which resolve to multiple IPs are also supported, although they generate multiple rules.

% sudo iptables --append FORWARD --protocol tcp --destination www.google.com --dport 443 --jump DROP
% sudo iptables -nL FORWARD
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DROP       tcp  --  0.0.0.0/0            74.125.224.147       tcp dpt:443
DROP       tcp  --  0.0.0.0/0            74.125.224.145       tcp dpt:443
DROP       tcp  --  0.0.0.0/0            74.125.224.148       tcp dpt:443
DROP       tcp  --  0.0.0.0/0            74.125.224.144       tcp dpt:443
DROP       tcp  --  0.0.0.0/0            74.125.224.146       tcp dpt:443
share|improve this answer

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.