Ubuntu中修改主机名

显示当前的hostname

hostnamectl


修改hostname

step 1. 使用hostnamectl

hostnamectl set-hostname ubuntu-cosmos

step 2. 修改/etc/hosts

ubuntu@ubuntu-cosmos:~$ cat /etc/hosts

127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

ff02::3 ip6-allhosts

127.0.1.1 ubuntu-cosmos ubuntu-cosmos

127.0.1.1 ubuntu-xenial ubuntu-xenial

step 3. 修改/cloud.cfg

ls -l /etc/cloud/cloud.cfg

修改preserve_hostname: true

你可能感兴趣的:(Ubuntu中修改主机名)