Longshot; Conditional '/etc/hosts' depending on an iface's subnet?

Christopher Browne cbbrowne-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Wed Dec 2 18:01:00 UTC 2009


On Wed, Dec 2, 2009 at 3:23 AM, Brandon Sandrowicz <bsandrow-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> On Mon, Nov 30, 2009 at 9:55 PM,  <jvetterli-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f at public.gmane.org> wrote:
>>
>> How about a script that read, modifies, and rewrites your hosts file?
>
> Or two different hosts files (/etc/hosts.work, /etc/hosts.home) and a
> symlink to the currently used one (e.g. `ln -s hosts.home
> /etc/hosts`)? Then maybe a script that can quickly swap them by hand
> (manually running the script) or automatically (cronjob to evaluate
> the current network and link to the correct hosts file).

Or a cfengine stanza...

 athome::
  { /etc/hosts
     EmptyEntireFilePlease
     AppendIfNoSuchLine "# This is managed via cfengine; edit in
/etc/cfengine/manage-hosts"
     AppendIfNoSuchLine "127.0.0.1       localhost.localdomain   localhost"
     AppendIfNoSuchLine "192.168.0.1  workhost1"
 }
 athome::
  { /etc/hosts
     EmptyEntireFilePlease
     AppendIfNoSuchLine "# This is managed via cfengine; edit in
/etc/cfengine/manage-hosts"
     AppendIfNoSuchLine "127.0.0.1       localhost.localdomain   localhost"
     AppendIfNoSuchLine "192.168.0.1  homehost1"
 }

There's certainly more than one way to skin the cat :-)

I'd strongly urge putting a comment into the /etc/hosts candidates to
indicate where the REAL data is, and that give some hint as to how to
fix things properly, to reduce the level of surprise.

If "magic happens" and data magically changes in /etc/hosts, that will
come as more of a surprise than if someone decides to edit it and
discovers the preface:

# /etc/hosts is being managed by my scripts in /var/spool/fiddle-hosts
#    current contents based on /var/spool/fiddle-hosts/hosts.at.home
-- 
http://linuxfinances.info/info/linuxdistributions.html
Joan Crawford  - "I, Joan Crawford, I believe in the dollar.
Everything I earn, I spend." -
http://www.brainyquote.com/quotes/authors/j/joan_crawford.html
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list