Can't change hostname or FQDN on Ubuntu 14.04 LEMP droplet

March 4, 2015 10.3k views
LEMP Email Linux Basics Django

When I set up the droplet (for lack of an imagination at the time), I set the name to "main". I have one droplet, so that seemed fairly logical. So I set up root ssh access and type "hostname" and it gives me "main". Same deal when I type "hostname -f". Well, I'm trying to set up Exim4 to send mail from my Django app (I only need to send, not receive) and I added " main" and "<myip> main" to /etc/hosts. I then executed "service hostname restart" and "hostname -f" only returned "main". I even rebooted (something I try to avoid doing) and it still comes back "main". Not sure why this is...

I'm guessing, but I'm not 100% sure, that's why when I use the command "echo test message | mail -s test" I'm not getting an email at (too many emails???). If it isn't absolutely necessary to have hostnames set up to use exim or sendmail (does anybody know if sendmail is installed by default on Ubuntu LEMP droplets), I'd like to avoid it because its caused me such a headache.

Any help will render me eternally grateful to your apparent awesomeness.

3 Answers

You'll want to update the hostname in both /etc/hostname and /etc/hosts before running service hostname restart

On newer systems running systemd (e.g. Ubuntu 16.04), you should use:

  • sudo hostnamectl set-hostname new-name
  • It worked for me, thanks!

  • @asb
    im on ubuntu 16.04
    i changed both places but having this error

    Failed to restart hostname.service: Unit hostname.service is masked.

    what should i do?

    • @newbie I updated my answer above. On 16.04, you should use the new hostnamectl command.

for others coming here like me... you don't need to run service hostname restart if you are using
hostnamectl command.

Have another answer? Share your knowledge.