Change the hostname of your root server

Skip to main content
Du bist hier:
Drucken

Change the hostname of your root server

The hostname is the name your server uses to identify itself, for example in the command prompt or when sending emails. You set it directly in your server’s operating system. That way it is kept permanently, even after a restart.

Linux (Ubuntu, Debian and others)

  1. Log in as root via SSH.
  2. Set the new name. Use only the first part, so server instead of server.musterdomain.ch:
    hostnamectl set-hostname server
  3. Open the file /etc/hosts and adjust the line starting with 127.0.1.1. If the line is missing, add it:
    127.0.1.1 server.musterdomain.ch server
  4. To make sure the old name does not come back after the next restart, create this file as well:
    printf 'preserve_hostname: truenmanage_etc_hosts: falsen' > /etc/cloud/cloud.cfg.d/99-hostname.cfg

    If there is no /etc/cloud folder on your server, you can skip this step.

  5. Check the result with hostname and hostname -f. The first command shows server, the second server.musterdomain.ch.

The new name takes effect immediately. In an SSH session that is already open, it appears in the command prompt only after you log in again.

Windows Server

  1. Open PowerShell as administrator.
  2. Set the new name:
    Rename-Computer -NewName "SERVER" -Restart

The server restarts and then uses the new name. On Windows, the name can be at most 15 characters long.

Servers in the vServerPanel

For a server in the vServerPanel, you change the hostname directly in the panel in the «Overview» tab of your server. The panel sets the name in the system right away, no restart needed.

Don’t forget reverse DNS

If you run a mail server on your server, also update the reverse DNS to the new name: Change reverse DNS (PTR) for your server.

Related Post