Linux - if I change the hostname, which services need to be restarted?
I'm making some system hostname changes across a few environments and this got me thinking...
When I change a server's hostname (live), what needs to be modified and which system services require a restart? Assume this is done online without a reboot.
I encounter a lot of systems built by other people where hostname changes are made in-flight, but the changes either do not persist across a reboot, or I notice that /var/log/messages
are stamped with a different hostname.
I regularly follow:
- Run
hostname <new-short-hostname>
- Modify
/etc/hosts
according to these guidelines. - Modify
/etc/sysconfig/network
On the daemon side...
- sendmail/postfix (matching hostname is required)
- cups (print daemon may stop with bad hostname)
- syslog/rsyslog (hostname is logged along with system messages)
- httpd (proper hostname is required)
What else requires attention?
This depends on the distribution. From your post, it looks very much like you are using either RHEL or CentOS. That's what I'll assume in my answer.
A lot of services look at the server's hostname, so it is very hard to generally give a complete overview of which services you need to restart. However, be aware of the following:
- Some Postfix installs have the hostname hardcoded in config as well.
- Same goes for Apache
- If you use NFS, you need to care for that
- On RHEL HA clusters you need to care for the cluster configuration
Usually, I also issue hostname new.host.name
to set the hostname without rebooting.
Also, I grep through /etc
and subdirs (config files) to find anywhere the server hostname has been set. Same goes for configuration files of custom compiled software.
Another thing to be aware of is external dependencies. In the environments I usually work with, things like Monitoring, Backup and Configuration Management are also dependant on the hostname of the server, and a lot of stuff will break if this is not taken into consideration.