After modifying /etc/hosts, which service(s) need(s) to be restarted for the change to take effect?
- 72,312
- 2,557
- 3
- 20
- 24
9 Answers
You don't need to restart any services.
When tested on a 14.04 server installation, the changes were reflected immediately.
The only service that I think could be related is 'networking', but it's unnecessary to restart it.
- 20,241
You can try: (Disclaimer: Don't run it if you're connected via SSH)
sudo ifconfig eth0 down
sudo ifconfig eth0 up
(substitute eth0 with your network card)
but Arronical is right in theory: You don't need it.
- 103
- 189
- 7
You need to restart systemd-hostnamed service which is a system service that may be used to change the system's hostname and related machine metadata from user programs.
/bin/systemctl restart systemd-hostnamed
- 201
If you use dnsmasq (is set by default), then do following:
$ pkill -HUP dnsmasq
Theoretically, changes to the /etc/hosts file take effect immediately.
But, if you get old hostname after this
$ hostname
then, either reboot or restart your network connection... that should show you the right hostname.
- 72,312
- 778
- 6
- 14
For the most part etc/hosts changes should be recognized immediately. If you add a new entry then ping it by name on the machine hosting the etc/hosts file it will most likely ping, that means the etc/hosts update has been recognized by DNS. On a pihole system if you restart the DNS resolver it will pick up the newly-added/edited etc/hosts entries. Most likely it's a function of whatever program is trying to utilize the hosts entries, did it read the current stuff or did it read just at boot time, or like pihole, will it reread by restarting a simple internal function?
- 51
- 1
- 2
Actually I noticed that postfix might benefit of a restart to include the new hosts in its local host file version that is available here /var/spool/postfix/etc/ (ubuntu 16.04)
- 266
You probably don't need to restart anything, unless there is a temporary cache of the DNS somewhere. To restart networking and clear the DNS cache on Debian and Ubuntu:
sudo /etc/init.d/networking restart
- 221
I kept getting an error, and google took me to this question. I thought I needed to restart some service, but actually I found it was my fault:
$ ping remote_hostname
ping: unknown host remote_hostname
The reason why hosts wasn't recognising a new entry was a typo in the IP address:
##.2480.##.## remote_hostname
- 11