How to set Hostname in Ubuntu

Setting Hostname in Ubuntu 15.04

Setting hostname in your Ubuntu server is very easy. Use the following command to set/ change the hostname in you ubuntu server. Please replace hostname with name of your choice.

echo "hostname" > /etc/hostname
hostname -F /etc/hostname

Update /etc/hosts

Next, edit your /etc/hosts file to resemble the following example, replacing hostname with your chosen hostname, example.com with your system’s domain name, and 12.34.56.78 with your system’s IP address. As with the hostname, the domain name part of your FQDN does not necessarily need to have any relationship to websites or other services hosted on the server (although it may if you wish). As an example, you might host “www.something.com” on your server, but the system’s FQDN might be “mars.somethingelse.com.”

/etc/hosts

127.0.0.1 localhost.localdomain localhost
12.34.56.78 hostname.example.com hostname

If you have IPv6 enabled on your Ubuntu, you will also want to add an entry for your IPv6 address, as shown in this example:

/etc/hosts

127.0.0.1 localhost.localdomain localhost
12.34.56.78 hostname.example.com hostname
2600:3c01::a123:b456:c789:d012 hostname.example.com hostname
next article

Leave a Reply