1. 使用hostnamectl命令修改
修改主机名为linux
root@debian:~# hostnamectl set-hostname linux输入hostnamectl命令查看主机名是否已修改
root@debian:~# hostnamectl
Static hostname: linux输出linux即说明修改成功
最后reboot重启下机器
2.手动修改
需编辑/etc/hostname和/etc/hosts两个文件
2.1:编辑/etc/hostname
root@debian:~# vi /etc/hostname #通过vi命令编辑内容为linux
root@debian:~# cat /etc/hostname #查看修改结果
linux
2.2:编辑/etc/hosts
将127.0.1.1的debian修改为linux
root@debian:~# vi /etc/hosts
127.0.0.1 localhost
127.0.1.1 debian
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
查看修改结果
root@debian:~# cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 linux
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
再reboot重启机器
评论