Ubuntu: Changing Hostname from Command Line

As described at it’s straight forward:

sudo /bin/hostname mynewhostname

Supplying the path to the binary is for security reasons, I guess, to make sure we have the right bin (eventhough it could have been replaced there, too…).

But the people at debianadmin.com forgot to mention in order to avoid “hostname: Unknown Host” you have to

sudo edit /etc/hosts

and change it there, too!

2 Comments

  1. Marcin Szamotulski said,

    Monday, 4th May 2009 at 18:42

    I had to change my host name, and I followed these instructions. Everything works ok (sysctl kernel.hostname give the new hostname) but the cron which is trying to send emails to the old hostname and I get a lot of email notifications. How do cron access for hostname (I do not see this in man pages)?
    I’ve checked for any env. variables and there is nothing what contains my old hostname. I also made grep -r oldhostname in \etc directory (a desperaccy act) and I do not find my old hostname.

    Thanks for any help.

    • Raghu Prasad said,

      Monday, 24th Aug 2009 at 14:29

      Have you tried re-starting the cron daemon?

      /etc/init.d/cron restart

      -Raghu


Post a Comment