Linux - change the hostname in the CLI

偶尔善良 提交于 2020-03-18 11:32:51

问题


I don't know how to search for this and that is why I asked for it (all my searches did not reveal any relevant information).

I have a Fedora 18 server that looks like this:

[root@dhcp-192-168-5-100 ~]#

I want to change that to:

[root@server1 ~]#

Currently, this machine is set to get IP through DHCP, but that is not the IP address of the machine and that is why I need to change the CLI to something more relevant.

Thank you


回答1:


you can type "hostname HOSTNAME" where HOSTNAME is the new name you want. The next time you log in / connect via ssh, that's what you'll see.




回答2:


  1. Edit /etc/sysconfig/network and change/add HOSTNAME variable like so HOSTNAME=server1.domain.com After restart it should have server1.
  2. Edit /etc/hosts and add server1 and server1.domain.com to 127.0.0.1 line, so it will look like: 127.0.0.1 localhost.localdomain localhost server1 server1.domain.com

More about network file you can read here: https://docs.fedoraproject.org/en-US/Fedora/15/html/Deployment_Guide/ch-The_sysconfig_Directory.html#s2-sysconfig-network




回答3:


Just found this and this is described pretty good.

   [root@dhcp-192-168-5-100 ~]# hostname MYHOSTNAME

Change hostname in Feodora




回答4:


  1. Add "yournewhostname" into /etc/sysconfig/network in the HOSTNAME field..
  2. Add "yournewhostname" into /etc/hosts for 127.0.0.1
  3. echo "yournewhostname" > /proc/sys/kernel/hostname or service hostname

IMPORTANT: logout and log back in.



来源:https://stackoverflow.com/questions/14636473/linux-change-the-hostname-in-the-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!