iptables
(and ip6tables
) functions on a layer of the OSI network model which does not have any concept of a DNS name -- it deals with IPv4 addresses (and ip6tables
deals with IPv6 addresses), as @vidarlo says. But, let's say you wanted to ignore that. And it's actually quite simple.
All you need to do is, on every connection attempt, perform a reverse DNS lookup against the IP address which iptables
/ip6tables
encounters, before it decides whether to allow the connection or not.
However, there are significant problems that emerge:
- Performance. Performing such a lookup on every connection will absolutely murder any performance you would otherwise expect on that interface. You probably don't want that, so you could set up a caching DNS server, but that leads into two other issues.
- CDNs exist. Just because Cloudflare or AWS or Digital Ocean is serving up an IP address for the
microsoft.zip
domain right now does not mean you'll get that IP address the next time you do a lookup. And additionally, if you decide you're going to block the entirety of Cloudflare/AWS/Digital Ocean because they allow for .zip-hosted domains, well. Good luck.
- Reliability. In order to get the DNS name from an IP address, you need to perform a RDNS lookup, as I mentioned above. But there is absolutely no requirement for anyone to provide A or AAAA records. Which means that if you do a RDNS lookup for an IP address, it doesn't have to return any results in the .zip gTLD (or, it could return some Cloudflare/AWS name instead). And while we've all seen the big lists of domain purchases, what you won't get is any subdomains. So someone may buy
amazon.zip
and you may assume that they'll create aws.amazon.zip
or s3.amazon.zip
or www.amazon.zip
, but you won't actually know until you do a lookup. And the answer may change, without warning; the only way to know for sure what subdomains exist is to be the domain owner or the registrar.
So what you're left with is that you need to create some method of finding out what .zip domains exist, then find out what IP addresses those domains use, then find all possible subdomains those domains are using, then manage a database of domain/IP/TTL and keep it updated, and then allow iptables
/ip6tables
to read from that (but you'd probably be better served with something like Snort or Suricata).
See? Simple.