The right way to change hostname on Debian 9 Linux

This tutorial will information you thru the steps required to alter the hostname in your Debian 9 system.

The hostname is about on the time when the Debian working system is put in or if you’re spinning up a digital machine it’s dynamically assigned to the occasion at startup.

The tactic described on this tutorial will work with out the necessity of restarting your Linux system.

Conditions

Earlier than persevering with with this tutorial, be sure to are logged in as a person with sudo privileges.

Show the Present Hostname

To view the present hostname, enter the next command:

As you may see within the picture above, the present hostname is about to host.linuxize.com.

Change the Hostname

A hostname is a label that identifies a machine on a community and ought to be distinctive inside the community infrastructure. It is strongly recommended to make use of a fully-qualified area identify (FQDN) because the system hostname.

The next steps define tips on how to change the hostname in Debian 9.

  1. Change the hostname utilizing hostnamectl.

    In Debian 9, to alter the system hostname and associated settings you should utilize the hostnamectl command.

    For instance, to alter the system hostname to host.instance.com, you should utilize the next command:

    sudo hostnamectl set-hostname host.instance.com

    The hostnamectl command doesn’t produce output. On success, Zero is returned, a non-zero failure code in any other case.

  2. Edit the /and so forth/hosts file.

    Open the /and so forth/hosts file and change your previous hostname with the brand new one.

    /and so forth/hosts

    127.0.0.1 localhost
    127.0.0.1 host.instance.com

    # The next strains are fascinating for IPv6 succesful hosts
    ::1 localhost ip6-localhost ip6-loopback
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters

Confirm the Change

To confirm that the hostname was efficiently modified, as soon as once more use the hostnamectl command:

Static hostname: host.instance.com
Icon identify: computer-vm
Chassis: vm
Machine ID: 2cc2688b8138434a81dd7b3133e66b2e
Boot ID: e378a0971e9e415cb70e7e953a2362bc
Virtualization: qemu
Working System: Debian GNU/Linux 9 (stretch)
Kernel: Linux 4.9.0-7-amd64
Structure: x86-64

and it’s best to see your new server identify printed on the console.

Conclusion

This tutorial we’ve got proven you tips on how to simply change your Debian server hostname with out restarting the machine.

Be happy to depart a remark in case you have any questions.

Supply

Germany Devoted Server

Leave a Reply