1

This is a shot in the dark here ...

I'm using a service called Strato-Server-Cloud which is basicaly a rudimentary version of AWS or Google-Compute. They changed their interface and/or engine recently. Ever since, all new Ubuntu 16 instances I create have the problem of thier hostname being reverted on reboot.

Here is what I usually do:

/etc/hostname

www.example.com

/etc/hosts

127.0.0.1 www.example.com www
[...]

On Ubuntu 16 additionally:

hostnamectl set-hostname www

After doing the steps above:

hostname -> www
hostname -f -> www.example.com

hostnamectl

Static hostname: www
Icon name: computer-vm
Chassis: vm
Machine ID: [ID]
Boot ID: [ID]
Virtualization: microsoft
Operating System: Ubuntu 16.04.1 LTS
Kernel: Linux 4.4.0-59-generic
Architecture: x86-64

After reboot rebooting

hostname -> XXX
hostname -f -> XXX.strato.net

hostname-ctl

Static hostname: www
Transient hostname: XXX
Icon name: computer-vm
Chassis: vm
Machine ID: [ID]
Boot ID: [ID]
Virtualization: microsoft
Operating System: Ubuntu 16.04.1 LTS
Kernel: Linux 4.4.0-59-generic
Architecture: x86-64

Note the transient hostname

Oddly enough the hosts and hostname files are intact.

I Also tried changing /etc/init/hostname.conf to the following

description     "set system hostname"

start on startup

task
exec hostname -b -F /etc/hostname.mod; full=$(cat /etc/hostname.mod);short=(${full//./ }); hostnamectl set-hostname $short

I put the hostname also in /etc/hostname.mod to ensure there is no overwriting going on. Executing the above exec-statement manually fixes everything but it doesn't seem to be effective during the boot-sequence ...

Unfortunately I'm pretty lost here ... I would assume the /etc/init/hostname.conf gets executed during boot but then the hostname gets overriden by another script? Has anyone ever had such an issue and knows how to fix it? I guess I could look into some linux version of a file-spy that documents what processes touch which files and find the offending script that way ... This does sound like a lot of work however ...

If someone could at least point out the livecycle of the hostname, that is the steps of how it is determined and where one could hook into this would already help me a lot.

Thanks in advance for your time and effort

Edit

I guess it would also help to explain why this is bad :-) OpenLDAP refuses to work correctly in STARTTLS mode if the hostname isn't properly configured. Since I never had the problem of not being able to change the hostname I don't know what other service might malefunction as well. A minimal solution to the problem would therefor have to become effective before service like OpenLDAP are started.

  • 1
    How does this computer get its IP address? dhcp? If yes, try to delete host-name from the request line in /etc/dhcp/dhclient.conf. – Doug Smythies Jan 23 '17 at 15:01
  • @doug Mister Smythies you da man! You know of all the things I considered like their hypervisor messing with the virtual disk image on reboot, I never imagined it to be something this stupid. Indeed there was a host-name directive and deleting it fixed everything. Make your comment an anwser and I accept it. – user3240383 Jan 23 '17 at 15:28
4

For computers that get their IP address via dchp, the default client file, /etc/dhcp/dhclient.conf, includes asking for what the host-name should be in the request:

request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;

You can remove that from the request:

request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;

I am not sure if: There might be unintended side effects; The domain-name should also be deleted from the request.

  • Thanks again. Should unintended side effects arise in the future im going to add them to my question. Pending that everything seems fine. – user3240383 Jan 23 '17 at 16:05
0

Old post, I know, but this helped me solve the same problem. I'm updating this for future search engine users experiencing the same problem.

It wasn't hostnamectl's fault this time.

If you're trying to change the hostname on a VPS server and it just doesn't want to change - your VM may be getting its hostname from the host machine/hypervisor.

In my case, I had to log into the VPS provider dashboard and change the hostname there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.