# [SOLVED] Ignore hostname from DHCP server.

## Jhedron

Long story short: my shiny, new wireless router has some issues so I've had to fall back on the routing capabilities of the Zyxel P-660H-D1 provided by my ISP. This is the first time I've had to use the routing capabilities of the device. Unlike every other home router I've had, the Zyxel is trying to assign hostnames to all of my devices via DHCP. It's getting annoying because hostnames like "dhcppc3" aren't all that useful to me. Since I apparently don't have access to the settings which control these hostnames, is there a way to tell Network Manager to ignore the DHCP hostname and stick with the hostname I've defined for the machine?

Relevant lines from my log:

```
Aug 04 22:31:33 alexandra NetworkManager[307]: <info> (lan0): DHCPv4 state changed preinit -> reboot

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   address x.x.x.x

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   prefix 24 (255.255.255.0)

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   gateway x.x.x.x

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   hostname 'dhcppc0'

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   nameserver 'x.x.x.x'

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   nameserver 'x.x.x.x'

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   domain name ''

Aug 04 22:31:33 alexandra NetworkManager[307]: nm_ip4_config_add_domain: assertion 'strlen (domain) > 0' failed

Aug 04 22:31:33 alexandra NetworkManager[307]: <info>   domain name ''

Aug 04 22:31:33 alexandra NetworkManager[307]: nm_ip4_config_add_domain: assertion 'strlen (domain) > 0' failed

Aug 04 22:31:33 alexandra NetworkManager[307]: <info> Activation (lan0) Stage 5 of 5 (IPv4 Configure Commit) scheduled...

Aug 04 22:31:33 alexandra NetworkManager[307]: <info> Activation (lan0) Stage 5 of 5 (IPv4 Commit) started...

Aug 04 22:31:34 alexandra NetworkManager[307]: <info> (lan0): device state change: ip-config -> secondaries (reason 'none') [70 90 0]

Aug 04 22:31:34 alexandra NetworkManager[307]: <info> Activation (lan0) Stage 5 of 5 (IPv4 Commit) complete.

Aug 04 22:31:34 alexandra NetworkManager[307]: <info> (lan0): device state change: secondaries -> activated (reason 'none') [90 100 0]

Aug 04 22:31:34 alexandra NetworkManager[307]: <info> NetworkManager state is now CONNECTED_GLOBAL

Aug 04 22:31:34 alexandra NetworkManager[307]: <info> Policy set 'Wired connection 1' (lan0) as default for IPv4 routing and DNS.

Aug 04 22:31:34 alexandra NetworkManager[307]: <info> Setting system hostname to 'dhcppc0' (from DHCPv4)
```

And here's the hostname information for the same machine:

```
$ hostnamectl

   Static hostname: alexandra

Transient hostname: dhcppc0

         Icon name: computer-desktop

           Chassis: desktop

        Machine ID: xxxxxxxxxx

           Boot ID: xxxxxxxxxx

  Operating System: Gentoo/Linux

            Kernel: Linux 3.15.8-gentoo

      Architecture: x86-64
```

Last edited by Jhedron on Wed Aug 06, 2014 3:10 am; edited 1 time in total

----------

## wraeth

If you use dhcpcd as your DHCP client backend, the you should be able to set something up in /etc/dhcpcd.conf.

```
# 

# Options for interface enp2s10 only

#

# This interface only below this point

interface enp2s10                     

# Send this hostname to the DHCP server

hostname cerberus2

```

See man dhcpcd.conf for more configuration options.

You should also double-check that your local hostname is configured correctly in the appropriate locations - /etc/conf.d/hostname for OpenRC and by using the command hostnamectl for systemd.

----------

## Jhedron

 *wraeth wrote:*   

> If you use dhcpcd as your DHCP client backend, the you should be able to set something up in /etc/dhcpcd.conf.
> 
> ```
> # 
> 
> ...

 

Thanks for pointing me to dhcpcd.conf. I forgot that NetworkManager doesn't handle the DHCP stuff itself. I first tried setting the hostname explicitly, as in your example:

```
# Should send the current system hostname, but didn't work...

#hostname

# ...so set the hostname explicitly.

hostname alexandra
```

When that didn't work, I noticed the following line:

```
option domain_name_servers, domain_name, domain_search, host_name
```

After reading what the man page had to say about it, I tried removing host_name. That seemed to do the trick.

----------

## UberLord

OR, if you don't want a DHCP derivated hostname, set one! local setting > DHCP always  :Smile: 

----------

## Jhedron

 *UberLord wrote:*   

> OR, if you don't want a DHCP derivated hostname, set one! local setting > DHCP always 

 

I thought I did have a hostname set. I use systemd, so I ran the following when I setup my machine:

```
# hostnamectl set-hostname alexandra
```

And I have this:

```
$ cat /etc/hostname

alexandra

$ hostnamectl

   Static hostname: alexandra

         Icon name: computer-desktop

           Chassis: desktop

        Machine ID: xxxxxxxxxx

           Boot ID: xxxxxxxxxx

  Operating System: Gentoo/Linux

            Kernel: Linux 3.15.8-gentoo

      Architecture: x86-64

```

Is there something else I need to do to make sure I have a hostname set?

----------

## dE_logics

Dhcpcd can't ignore the hostname sent by the server. I would call this a vulnerability. Time to dump dhcpcd.

----------

## UberLord

 *dE_logics wrote:*   

> Dhcpcd can't ignore the hostname sent by the server. I would call this a vulnerability. Time to dump dhcpcd.

 

Time to dump your ignorance!

1) Don't request it in dhcpcd.conf

2) If the server send it anyway, tell dhcpcd not to use it.

```

nooption hostname
```

3) 30-hostname hook script will not use it UNLESS a hostname has not already been set OR the force hostname option is set, which it isn't by default.

----------

## dE_logics

I'll get it back on board next time.

Thanks for that.

----------

