【Linux】Ubuntu下修改主机名

目标

安装Ubuntu系统时设置的主机名太长了,想改简单些

步骤

1. 切换root用户

hostname文件在普通用户下没有写权限,所以切换到root用户进行修改操作。使用su进行切换时,提示认证失败,可通过sudo passwd重置root用户密码后在进行用户切换。

test@test-virtual-machine:/$ su                 #切换root用户
Password: 
su: Authentication failure                      #认证失败
test@test-virtual-machine:/$ sudo passwd        #修改root用户密码
[sudo] password for test: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
test@test-virtual-machine:/$ su                 #切换root用户
Password:                                       #输入新密码
root@test-virtual-machine:/# vi /etc/hostname   #编辑hostname

2. 修改/etc/hostname

(备注:其他发行版修改/etc/sysconfig/network的HOSTNAME)

root@test-virtual-machine:/# vi /etc/hostname

3. 修改/etc/hosts

root@test-virtual-machine:/# vi /etc/hosts

4. 重启系统

root@test-virtual-machine:/# reboot

5. 验证

输入hostname命令查看系统当前的主机名为修改后的主机名:testserver

test@testserver:~$ hostname
testserver
【微信公众号】“粒粒的测试笔记

猜你喜欢

转载自www.cnblogs.com/yllil/p/13210175.html