Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 50063

Summary: have net.ethx auto-manage dhcp entries in /etc/hosts
Product: Gentoo Linux Reporter: Evan Teran <evan.teran>
Component: [OLD] Core systemAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED INVALID    
Severity: enhancement    
Priority: High    
Version: 2004.1   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: example implementation (lines 106/217/218 are relavent changes)
improvment, implements it as postup/predown functions (all changes at bottom now)

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.