# dhcpcd not setting hostname

## gren

I'm running dhcpcd 3.0.16-r1 (and I've tried the currently masked 3.0.17), and while it can get an IP, it doesn't set the hostname. -H has no effect. Version 2.0.5-r1 works fine. Does anyone know what I'm doing wrong?

```
root@localhost ~ # emerge --info

Portage 2.1.2.2 (default-linux/x86/2006.1/desktop, gcc-4.1.1, glibc-2.5-r0, 2.6.19-gentoo-r5 i686)

=================================================================

System uname: 2.6.19-gentoo-r5 i686 AMD Athlon(tm) 64 Processor 4000+

Gentoo Base System release 1.12.9

Timestamp of tree: Tue, 17 Apr 2007 13:00:01 +0000

dev-java/java-config: 1.3.7, 2.0.31-r5

dev-lang/python:     2.4.3-r4

dev-python/pycrypto: 2.0.1-r5

sys-apps/sandbox:    1.2.17

sys-devel/autoconf:  2.13, 2.61

sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10

sys-devel/binutils:  2.16.1-r3

sys-devel/gcc-config: 1.3.15-r1

sys-devel/libtool:   1.5.22

virtual/os-headers:  2.6.17-r2

ACCEPT_KEYWORDS="x86"

AUTOCLEAN="yes"

CBUILD="i686-pc-linux-gnu"

CFLAGS="-O2 -march=athlon-xp -pipe"

CHOST="i686-pc-linux-gnu"

CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"

CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/gconf /etc/java-config/vms/ /etc/revdep-rebuild /etc/terminfo"

CXXFLAGS="-O2 -march=athlon-xp -pipe"

DISTDIR="/usr/portage/distfiles"

FEATURES="distlocks metadata-transfer parallel-fetch sandbox sfperms strict"

GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/linux/distributions/gentoo"

MAKEOPTS="-j2"

PKGDIR="/usr/portage/packages"

PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"

PORTAGE_TMPDIR="/var/tmp"

PORTDIR="/usr/portage"

SYNC="rsync://rsync.gentoo.org/gentoo-portage"

USE="X aac alsa arts berkdb bitmap-fonts cairo cdr cli cracklib crypt cups dbus dri dvd dvdr eds emboss encode esd fam firefox fortran gdbm gif gnome gpm gstreamer gtk hal iconv ipv6 isdnlog jpeg kde ldap libg++ mad midi mikmod motif mp3 mpeg ncurses nls nptl nptlonly nsplugin nvidia ogg opengl oss pam pcre perl png ppds pppd python qt3 qt4 quicktime readline reflection sdl session spell spl ssl tcpd truetype truetype-fonts type1-fonts unicode vorbis win32codecs x86 xinerama xml xorg xv zlib" ALSA_CARDS="intel8x0" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" ELIBC="glibc" INPUT_DEVICES="keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU" VIDEO_CARDS="nvidia"

Unset:  CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, LC_ALL, LDFLAGS, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY
```

```
root@localhost ~ # cat /etc/hostname

cat: /etc/hostname: No such file or directory
```

```
root@localhost ~ # cat /etc/conf.d/hostname

# /etc/conf.d/hostname

# Set to the hostname of this machine

HOSTNAME="localhost"
```

```
root@localhost ~ # cat /etc/conf.d/net

# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :]!).

dhcpcd_eth0="-H"
```

----------

## UberLord

Is your dhcp server actually sending out a hostname or is it resolvable?

----------

## UberLord

Also, try this patch against dhcpcd-3.0.17

http://dev.gentoo.org/~uberlord/dhcpcd-hostname.patch

----------

## UberLord

Bleh, that patch fails on linux.

Here's a tarball that does work on linux

http://dev.gentoo.org/~uberlord/dhcpcd-3.0.18_pre1.tar.bz2

----------

## gren

 *UberLord wrote:*   

> Bleh, that patch fails on linux.
> 
> Here's a tarball that does work on linux
> 
> http://dev.gentoo.org/~uberlord/dhcpcd-3.0.18_pre1.tar.bz2

 

With this version, I now get a hostname, but it's the short hostname. With dhcpcd 2.x, I got a hostname like dynXXX.example.com. 3.0.18_pre1 gives me just dynXXX:

 *Quote:*   

> # dhcpcd -H -d eth0
> 
> Info, eth0: dhcpcd 3.0.18_pre1 starting
> 
> ...
> ...

 

The hostname command doesn't work when called with most arguments:

 *Quote:*   

> # hostname # works
> 
> dynXXX
> 
> # hostname --fqdn # error
> ...

 

----------

## UberLord

If you do

```
hostname "dynXXX.example.com"
```

Do the --fqdn and --ip-address options then work?

----------

## gren

 *UberLord wrote:*   

> If you do
> 
> ```
> hostname "dynXXX.example.com"
> ```
> ...

 

Yes!

----------

## UberLord

http://dev.gentoo.org/~uberlord/dhcpcd-3.0.18_pre2.tar.bz2

Try that tarball, should work for you now  :Smile: 

----------

## gren

It works great! Thanks!

There is one little oddity. When I log in, the greeting on the console is "This is dynXXX.example.com.example.com ...". It looks like this might be coming from /etc/issue, which is part of baselayout.

----------

## UberLord

Watch this thread for replies until I can look into that some more as it is a dhcpcd bug.

----------

## MacMan45

Thank you for this!!

I have just set up my work machine on gentoo and this was something I had never encountered before (setting the hostname via dhcp).

Thanks for helping solve my problem :D

----------

## UberLord

 *gren wrote:*   

> It works great! Thanks!
> 
> There is one little oddity. When I log in, the greeting on the console is "This is dynXXX.example.com.example.com ...". It looks like this might be coming from /etc/issue, which is part of baselayout.

 

Is there a domain or search in /etc/resolv.conf?

If so, could you post it please or is it example.com?

----------

## gren

# Generated by dhcpcd for interface eth0

search example.com

nameserver A.B.C.D

nameserver A.B.X.Y

----------

## UberLord

Interesting. In that case you shouldn't need the domain tacked on to the hostname. If you do

hostname dynXXX

does hostname --fqdn still work?

----------

## gren

# hostname --fqdn # with hostname assigned by 3.0.18_pre2

dynXXX.example.com

# hostname --ip-address

A.B.C.D

# hostname dynXXX

# hostname --fqdn

hostname: Unknown host

# hostname --ip-address

hostname: Unknown host

----------

## UberLord

Very odd.

With dhcpcd-2.x, did you get "This is dynXXX.example.com.example.com ..." on the console too?

If not, please email me (uberlord@gentoo.org) the exact contents of the output of hostname, the /etc/resolv.conf file and if you can a wireshark trace of both the dhcpcd-2 and dhcpcd-3 transactions. Untouched, don't hide things.

Thanks

----------

## gren

 *UberLord wrote:*   

> Very odd.
> 
> With dhcpcd-2.x, did you get "This is dynXXX.example.com.example.com ..." on the console too?

 

I just downgraded to 2.0.5-r1, and yes, I still see that. I don't know if I upgraded something else that caused it to happen, or if I just never noticed it before. Whatever is happening, it seems to be just a minor display problem. Everything works OK.

----------

## UberLord

Here's a new beta tarball

http://dev.gentoo.org/~uberlord/dhcpcd-3.0.18_pre3.tar.bz2

Basically, if we have a domain or search path then we strip it from the hostname if it matches.

It should solve the issue.

----------

