总体来说就是修改 /etc/hostname 和 /etc/hosts 即可
/etc/hostname
vm1-ubuntu-svr
/etc/hosts
127.0.0.1 localhost 127.0.1.1 vm1-ubuntu-svr.localdomain vm1-ubuntu-svr # 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
/etc/hostname This file should only contain the hostname and not the full FQDN.(man hostname)
完整网域名称由主机名称与母网域名称两部份所组成,例如有一部服务器的本地主机名为myhost,而其母域名为example.com,那指向该服务器的完整网域名称就是myhost.example.com。虽然世界上可能有很多服务器的本地主机名是myhost,但myhost.example.com是唯一的,因此完整网域名称能识别该特定服务器。(完整网域名称)
也就是说,对于 myhost.example.com, /etc/hostname 中只用填写 myhost.
这个文件是用来记录 IP 与主机映射关系的静态文件,和 Windows 的 C:\Windows\System32\drivers\etc\hosts 功能是一样的。
格式:
IP_address canonical_hostname [aliases...]
127.0.0.1 localhost 192.168.1.10 foo.mydomain.org foo 192.168.1.13 bar.mydomain.org bar 146.82.138.7 master.debian.org master 209.237.226.90 www.opensource.org(man hosts)
别名可有可无
/etc/hostname
controller.openstack
127.0.0.1 localhost 127.0.1.1 controller.openstack controller # 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
man hostname
man hosts
Changing the hostname or computer name in ubuntu