系统:Ubuntu 16.04.4 LTS
(1)修改文件 /etc/hostname
aliyun
(2)修改文件/etc/hosts
添加一行:127.0.0.1 aliyun
修改前:
root@iZuf63u8pffjhthktgq2h0Z:~# cat /etc/hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.19.254.1xx iZuf63u8pffjhthktgq2h0Z iZuf63u8pffjhthktgq2h0Z
修改后:
root@iZuf63u8pffjhthktgq2h0Z:~# cat /etc/hosts
127.0.0.1 localhost
127.0.0.1 aliyun
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.19.254.1xx iZuf63u8pffjhthktgq2h0Z iZuf63u8pffjhthktgq2h0Z
如果不修改文件/etc/hosts,新建普通用户xiaxinkai后,使用sudo命令时,会发生如下错误:
xiaxinkai@aliyun:~$ sudo apt update
sudo: unable to resolve host aliyun
[sudo] password for xiaxinkai: