Gentoo Archives: gentoo-user

From: Alan McKinnon <alan.mckinnon@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] /etc/hosts include file?
Date: Fri, 08 Mar 2013 08:25:43
Message-Id: 5139A003.6030909@gmail.com
In Reply to: Re: [gentoo-user] /etc/hosts include file? by Pandu Poluan
1 On 08/03/2013 06:30, Pandu Poluan wrote:
2 >
3 > On Mar 8, 2013 5:27 AM, "Alan McKinnon" <alan.mckinnon@×××××.com
4 > <mailto:alan.mckinnon@×××××.com>> wrote:
5 >>
6 >> Anyone know if there's a way to get /etc/hosts to support the notion of
7 >> an include file? I did my homework and found nothing, maybe someone else
8 >> knows more.
9 >>
10 >> I really do need this, I have an app that discovers things on the
11 >> network and knows their address. This makes it's automated way into DNS
12 >> but takes a few days, and another app needs to use the fqdn right now.
13 >> So /etc/hosts is the way to go for the interim three days.
14 >>
15 >> I've worked around it by creating /etc/hosts.d/ containing a header and
16 >> a data file. cat the two and redirect to /etc/hosts.d/hosts and the real
17 >> hosts file is a symlink to that. It's a sub-directory as none of these
18 >> apps run as root and only root can modiy the real hosts file.
19 >>
20 >> This works well enough, but a supported include mechanism would make
21 >> life so much simpler, not to mention easier for my colleagues to
22 >> understand what the blazes I set up :-)
23 >>
24 >>
25 >>
26 >> --
27 >> Alan McKinnon
28 >> alan.mckinnon@×××××.com <mailto:alan.mckinnon@×××××.com>
29 >>
30 >>
31 >>
32 >
33 > An option would be to create a cron job which generates the hosts file
34 > every minute. The cron job should also insert a header on top of the
35 > hosts file telling:
36 >
37 > + this file (hosts) is dynamically generated
38 > + by a system cron job
39 > + the cron job's script location
40 >
41 > Besides, you said you're going to need this workaround only for a couple
42 > of days, so installing Samba4 might be an overkill.
43
44
45
46 I'm already doing something very much like that, I reckon I'll leave it
47 in place, and document it in the grand CYA tradition.
48
49 To be clear, it's not a temporary workaround - it's permanent. I do
50 network discovery every 12 hours and can find up to 7000 things on the
51 network, so now I know their hostname and address. This eventually makes
52 it's way into DNS, but DNS by design updates slowly and a second app (an
53 audit app) needs to resolve the names immediately. That's why hosts is
54 the perfect interim solution; in 3 days when the DNS update happens the
55 entry is removed from the hosts file.
56
57
58
59 --
60 --
61 Alan McKinnon
62 alan.mckinnon@×××××.com