# Don't want DHCP to set Hostname

## dman777

I don't want DHCP to set the host name. I'd rather the static hostname in the /etc/sysctl.conf be used. How can I stop DHCP from changing it?

----------

## depontius

AFAIK there is no "generic dhcp" option to retain the hostname. But for dhcpcd you can add to '/etc/conf.d/net' the line 'dhcpcd_eth0="-R"' and it will retain your desired hostname.  BTW, I thought the hostname was set in '/etc/conf.d/hostname', not in '/etc/sysctl.conf'.

----------

## dman777

wow..i must be loosing my head. ya, your right. it's hostname file. thanx

----------

## dman777

Hi,

That it worked! But only for awhile. For some reason, it's not working anymore. The net file still says 'dhcpcd_eth0="-R"' but it has reverted back to displaying my ISP IP address instead of the hostname default which I have set to "localhost" in the /etc/hostname file. Any suggestions?

----------

## eccerr0r

You could use your -c script of dhcpcd to change your hostname back as a possibility...

Supposedly dhcpcd shouldn't change your hostname unless -H is set in the options?  Is -H set somewhere?

----------

## dman777

naw, i can't find anywhere in the '/etc/conf.d/net' where the -H flag is used, so dhcpcd must rename the $HOSTNAME variable by default. 

ya, that's a good idea about the script. Actually, instead of making the script I'll just source the hostname file after dhcpcd has ran. I'll probably have it sourced in /etc/bash/bashrc since i want it global. would there be a better place to have it sourced instead?

----------

## depontius

I just got a rude surprise on my laptop this morning.  Earlier this week, "emerge -atuvDN world" picked up net-misc/dhcpcd-4.x.  It has completely change the back-end scripting methods, and broken all of my stuff.  For the moment, I've added "=>net-misc/dhcpcd-4" to /etc/portage/package.mask.  I plan to get it into /var/tmp/portage using the ebuild command, and start reading the man pages there in order to figure out how to adapt.  It looks as if the new stuff might actually be better and easier to use, but it's different, so change will be required.

Net:  If you're doing anything offbeat with post-dhcpcd scripting, the new release of dhcpcd-4 going stable this week will kill your stuff.

----------

## UberLord

Be fair - dhcpcd-4 has been sitting in unstable for months now. You should have had plently of time to review any changes and adapt accordingly   :Twisted Evil: 

----------

## Raffi

 *UberLord wrote:*   

> Be fair - dhcpcd-4 has been sitting in unstable for months now. You should have had plently of time to review any changes and adapt accordingly  

 

To be fair, some of us use the stable version unless there is a compelling reason to look at unstable. When this sort of change is pushed out as stable, it should be accompanied by a warning giving the user some idea of what is coming. I did see a message from my upgrade, but it had nothing to do with what really screwed me up (ie no mention of the change to scripting).

The only message printed was

```

LOG: unpack

dhcpcd-3 command line support enabled

LOG: postinst

You have installed dhcpcd with zeroconf support.

This means that it will always obtain an IP address even if no

DHCP server can be contacted, which will break any existing

failover support you may have configured in your net configuration.

This behaviour can be controlled with the -L flag.

See the dhcpcd man page for more details.

```

which really does not prepare you for the pain to come.

----------

## toralf

put a line like 

```
dhcp_eth0="nosendhost"
```

into your /etc/conf.d/net.

----------

## depontius

 *UberLord wrote:*   

> Be fair - dhcpcd-4 has been sitting in unstable for months now. You should have had plently of time to review any changes and adapt accordingly  

 

I normally run stable, unless there is something specific that I need in unstable.  I also generally keep an eye out here for packages that are causing problems for others who are running unstable, or who are even faster than me at keeping up with stable.  I knew there were some incompatibilities with dhcpcd, I just didn't know it was this close to going stable.  Knowing some of that in advance was how I could react and be running normally within 10 minutes, also.

I now have dhcpcd-4 "installed" in /var/tmp/portage and am trying to figure out how the heck to get my stuff running with it.  I used to use "/var/lib/dhcpcd/dhcpcd-eth0.info" to do my stuff, including writing /etc/dhsmasq-resolv.conf, /etc/hosts, hostname, switching afs on or off, switching pam between afs and standard logins, switching gdm between listening and not listening on tcp, etc, etc, etc.  That file no longer exists, and I see that there are better provisions for me to hook in, but I no longer see how to get my information, at least not in the few minutes I've been able to work with it.  "Real work" (chip design) says stick with dhcpcd-3, for now.

----------

## UberLord

 *depontius wrote:*   

> I now have dhcpcd-4 "installed" in /var/tmp/portage and am trying to figure out how the heck to get my stuff running with it.  I used to use "/var/lib/dhcpcd/dhcpcd-eth0.info" to do my stuff, including writing /etc/dhsmasq-resolv.conf, /etc/hosts, hostname, switching afs on or off, switching pam between afs and standard logins, switching gdm between listening and not listening on tcp, etc, etc, etc.  That file no longer exists, and I see that there are better provisions for me to hook in, but I no longer see how to get my information, at least not in the few minutes I've been able to work with it.  "Real work" (chip design) says stick with dhcpcd-3, for now.

 

Unpack the tarball somewhere and look in the dhcpcd-hooks dir. There is a basic compat shim that shows how to get the old variables from the new ones.

----------

## depontius

 *UberLord wrote:*   

> Unpack the tarball somewhere and look in the dhcpcd-hooks dir. There is a basic compat shim that shows how to get the old variables from the new ones.

 

I've been browsing around in there, but haven't had a lot of time to spend on it.  It looks like the information is now coming in on environment variables.  Of course right now I simply ". /var/lib/dhcpcd/dhcpcd-eth-.info" and get it from environment variables that way.

----------

## dman777

I haven't made any changes to my system since my last post and now it's working like it should showing the default $HOSTNAME again(localhost). Wierd....

----------

## UberLord

 *dman777 wrote:*   

> I haven't made any changes to my system since my last post and now it's working like it should showing the default $HOSTNAME again(localhost). Wierd....

 

Never rely on $HOSTNAME.

Instead, use the output of the hostname binary.

----------

