Gentoo Archives: gentoo-user

From: Mick <michaelkintzios@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Blocking a domain instead of an IP with ufw
Date: Sat, 01 Aug 2015 11:08:35
Message-Id: 201508011208.17888.michaelkintzios@gmail.com
In Reply to: Re: [gentoo-user] Blocking a domain instead of an IP with ufw by Meino.Cramer@gmx.de
1 On Saturday 01 Aug 2015 11:35:14 Meino.Cramer@×××.de wrote:
2 > Mick <michaelkintzios@×××××.com> [15-08-01 12:20]:
3 > > On Saturday 01 Aug 2015 10:48:15 Alan McKinnon wrote:
4 > > > On 01/08/2015 11:21, Meino.Cramer@×××.de wrote:
5 > > > > Hi,
6 > > > >
7 > > > > With ufw I want temporary block any access from my Gentoo PC to
8 > > > > certain domains. Since domain names change IP addresses I dont want
9 > > > > to block on base of the IP only.
10 > > > >
11 > > > > Is this possible with ufw?
12 > > >
13 > > > That is really not a good idea, which is why packet filtering firewalls
14 > > > seldom attempt it.
15 > > >
16 > > > It means that *every*single*packet* involves a reverse DNS lookup to
17 > > > get the (unreliable) DNS name (which might not even be listed at all),
18 > > > do a string comparison and make a block decision based on that. All of
19 > > > which is probably an order of magnitude more resource use that simply
20 > > > sending the packet out. There are optimizations of course, such as
21 > > > caching the results of previous lookups, but there's still a
22 > > > considerable overhead.
23 > > >
24 > > > There's a few ways around it:
25 > > >
26 > > > 1. Rethink your firewalling policy. Maybe you really don't need to
27 > > > block stuff and just think you do.
28 > > >
29 > > > 2. Do a DNS lookup and check the TTL. If it's high, say 86400 then it
30 > > > cannot change more than once a day. So you only need to do a lookup
31 > > > once a day. Write or get a script that looks up your banned domains
32 > > > every so often, gets the new IP if it changed and reload a new
33 > > > netfilter rule set.
34 > > >
35 > > > #2 is the correct approach for large firewalls with many users but does
36 > > > involves a quite sophisticated codebase, probably way more than you
37 > > > need for your 1 pc. Which brings us back to #1
38 > >
39 > > There's also the option to set in /etc/hosts:
40 > >
41 > > 127.0.0.1 safebrowsing.clients.google.com
42 > >
43 > > (Replace the google domain above with whatever you want to stop access
44 > > to).
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
69
70 If I recall right you are using dnsmasq on the PC you connect the tablet to?
71
72 In this case you can add in dnsmasq.conf:
73
74 address=/some-adnroid-site.com/127.0.0.1
75
76 This will cause any dns queries to this address from the tablet to fail, but
77 it will NOT block connections to relevant IP addresses. Not sure if this is
78 any easier than altering /etc/hosts on the tablet.
79
80 --
81 Regards,
82 Mick

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies