linux修改主机名的方法

linux修改主机名的方法

* 临时修改 
用hostname命令可以临时修改机器名,但机器重新启动之后就会恢复原来的值。

#hostname   //查看机器名
#hostname -I  //查看本机器名对应的ip地址

《
jb@panda:~$ hostname
panda
jb@panda:~$ hostname -I
192.168.10.39 
》

* 永久修改

      1)编辑文件/etc/hosts 将下面的一行

  127.0.1.1 xxxxx

  替换为

  127.0.1.1 newhostname

  2) 编辑 /etc/hostname文件 删除该文件的所有内容,添加newhostname
《里面只有原来的主机名》

  3)运行一下命令 hostname newhostname
《这个需要切换成root
su - root

普通用户,不行
jb@panda4460:~$ hostname 380
hostname: you must be root to change the host name

sudo 也不行
jb@panda4460:~$ sudo hostname 380
sudo: unable to resolve host panda4460

jb@panda4460:~$ hostname
380

换成root就好了
jb@panda4460:~$ su - root
Password: 
root@380:~# hostname 380
root@380:~# 
》
  3.退出root用户 改用一般用户登录即可











  注:

  其中 xxxxx为原来的主机名 newhostname为你想修改的主机名



how to avoid the warning: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName


Edit your httpd.conf and add your ServerName
nano /etc/apache2/httpd.conf

 

Add your server name:
ServerName YourHostName

 

Reboot the system for the new changes to take effect
sudo shutdown -r now

 

Done!
ctrl+d注销一下系统,再重登录
原文地址:https://www.cnblogs.com/vipzrx/p/3470990.html