Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 50063 - have net.ethx auto-manage dhcp entries in /etc/hosts
Summary: have net.ethx auto-manage dhcp entries in /etc/hosts
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-04 20:43 UTC by Evan Teran
Modified: 2004-05-06 18:01 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
example implementation (lines 106/217/218 are relavent changes) (net.eth0,8.82 KB, text/plain)
2004-05-04 20:44 UTC, Evan Teran
Details
improvment, implements it as postup/predown functions (all changes at bottom now) (net.eth0,8.91 KB, text/plain)
2004-05-04 20:57 UTC, Evan Teran
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Evan Teran 2004-05-04 20:43:57 UTC
it would be a very nice feature (and could actually simplify things) if the net.ethx scripts automatically added/removed entries from /etc/hosts on start and stop.  this is especially useful for those with laptops or generally DHCP driven addresses that are subject to change.  it is a trivial change too!.

examples (this works very well for me so far):

to add a line in the start:

echo "${ip} `hostname` # added by DHCP" >> /etc/hosts

then to remove it in stop:

sed -i "/^${ip} `hostname` # added by DHCP$/ d" /etc/hosts

i have an example version which seems to work flawlessly (though i'm sure you guys could give it even further enhancment).
Comment 1 Evan Teran 2004-05-04 20:44:51 UTC
Created attachment 30763 [details]
example implementation (lines 106/217/218 are relavent changes)
Comment 2 Evan Teran 2004-05-04 20:57:56 UTC
Created attachment 30764 [details]
improvment, implements it as postup/predown functions (all changes at bottom now)
Comment 3 Aron Griffis (RETIRED) gentoo-dev 2004-05-06 18:01:10 UTC
This isn't how DHCP should work.  If you do this then you're fooling yourself (well, okay, your machine ;-) into thinking that the hostname is associated with the address.  If you want to do that, it's fine, but it's not for everybody.

Instead, you should be using "dhcpcd -h hostname eth0" (where "hostname" is the preferred name of your machine) to request a certain name from the DHCP server.  If things are configured correctly, this will also result in an updated DNS entry for your hostname/address association.  In that case there is no need to update /etc/hosts at all.  To accomplish this you can set dhcpcd_eth0="-h hostname" in /etc/conf.d/net

Another alternative is to put your hostname on the same line with localhost so that you can always ping yourself, etc.

Anyway, your solution isn't a good one for most people.  Thanks for the suggestion, though.  Glad to hear you can make use of the preup and predown functions.