Cart
Article overview

Help article

Changing your hostname in Ubuntu 18.04

It is important to set a correct hostname on your VPS. The hostname is used by many applications to identify themselves on a network / the internet. Therefore, an incorrectly configured hostname can cause unexpected problems.


Checking the hostname

 

The current hostname can be retrieved with the command:

hostname -f

Changing the hostname

 

There are three methods to customize or view your hostname:

  • the hostnamectl-command
  • the /etc/hosts-file
  • the hostname-command

Only the changes of the first two remain intact after a restart. You change your hostname with these options as follows:
 

  • Hostnamectl:
    Use the command below and replace server.yourdomain.com with your desired hostname:
    hostnamectl set-hostname server.yourdomain.com

     

  • /etc/hosts:
    Open the /etc/hosts file with a text editor, for example:
    nano /etc/hosts
    The second line looks like this:
    127.0.1.1          server.yourdomain.com  server
    
    On this line, change server.yourdomain.com to the new hostname and replace ‘server’ with what is in front of yourdomain.com.

    Then save your changes (ctrl + x> y> enter) and restart your VPS.

    If you have not yet set a hostname, instead of the above example, you will see a placeholder with IP information, which looks like 123-123-123-123.colocation.transip.us

  • hostname:
    Use the command below and replace server.yourdomain.com with your desired hostname:
    hostname server.yourdomain.com
    Please note that with the hostname command, the changes do not persist after a reboot of your VPS.

 

Should you have any questions left regarding this article, do not hesitate to contact our support department. You can reach them via the ‘Contact Us’ button at the bottom of this page.

If you want to discuss this article with other users, please leave a message under 'Comments'.

Do you have a good idea?

Give us your idea! If it's popular we'll add it to the wishlist!

Has this article been helpful?

Thanks for your feedback!

Feedback? Let us know in the discussion below.

Comments

You can use Markdown to format your response.
Logged in as: transipdemo

Are you stuck?

Ask one of our specialists to assist you

Contact us