Gentoo Archives: gentoo-user

From: Meino.Cramer@×××.de
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Blocking a domain instead of an IP with ufw
Date: Sat, 01 Aug 2015 10:35:24
Message-Id: 20150801103514.GC4402@solfire
In Reply to: Re: [gentoo-user] Blocking a domain instead of an IP with ufw by Mick
1 Mick <michaelkintzios@×××××.com> [15-08-01 12:20]:
2 > On Saturday 01 Aug 2015 10:48:15 Alan McKinnon wrote:
3 > > On 01/08/2015 11:21, Meino.Cramer@×××.de wrote:
4 > > > Hi,
5 > > >
6 > > > With ufw I want temporary block any access from my Gentoo PC to certain
7 > > > domains. Since domain names change IP addresses I dont want to block
8 > > > on base of the IP only.
9 > > >
10 > > > Is this possible with ufw?
11 > >
12 > > That is really not a good idea, which is why packet filtering firewalls
13 > > seldom attempt it.
14 > >
15 > > It means that *every*single*packet* involves a reverse DNS lookup to get
16 > > the (unreliable) DNS name (which might not even be listed at all), do a
17 > > string comparison and make a block decision based on that. All of which
18 > > is probably an order of magnitude more resource use that simply sending
19 > > the packet out. There are optimizations of course, such as caching the
20 > > results of previous lookups, but there's still a considerable overhead.
21 > >
22 > > There's a few ways around it:
23 > >
24 > > 1. Rethink your firewalling policy. Maybe you really don't need to block
25 > > stuff and just think you do.
26 > >
27 > > 2. Do a DNS lookup and check the TTL. If it's high, say 86400 then it
28 > > cannot change more than once a day. So you only need to do a lookup once
29 > > a day. Write or get a script that looks up your banned domains every so
30 > > often, gets the new IP if it changed and reload a new netfilter rule set.
31 > >
32 > > #2 is the correct approach for large firewalls with many users but does
33 > > involves a quite sophisticated codebase, probably way more than you need
34 > > for your 1 pc. Which brings us back to #1
35 >
36 > There's also the option to set in /etc/hosts:
37 >
38 > 127.0.0.1 safebrowsing.clients.google.com
39 >
40 > (Replace the google domain above with whatever you want to stop access to).
41 >
42 > --
43 > Regards,
44 > Mick
45
46 Hi Mick,
47
48 yes this comes close to what I want, but it is not that easy to switch
49 on/off.
50
51 Background:
52 I have a Android tablet which I connected via Wifi to my PC and
53 started wireshark before the connection was etablished.
54
55 As soon the connection was there, the tablet starts to phone home.
56 I want to stop that for the case, when the tablet accesses those
57 domains, since in that case an tablet ID or whatever this
58 "anonymous identification" is called is transmitted.
59
60 Next came iptables into my mind since it is a configuration
61 item and not a phyical thing like a file.
62
63 Is there a way (for example via something below /proc or /sys) to
64 feed the contents of /etc/hosts into the kernel instead of using
65 the physical file?
66
67 Best regards
68 Meino

Replies

Subject Author
Re: [gentoo-user] Blocking a domain instead of an IP with ufw Mick <michaelkintzios@×××××.com>