Redhat7.2 在安裝的時候,會默認生成主機名:localhost. 那么如何修改成自己想要的自己名?
//格式為:用戶名@主機名
比如: [root@localhost ~]# 修改成[root@xiaolyu ~]#
我的目前已經是[root@xiaolyu ~]# 主機名(hostname)為xiaolyu ,可以修改為lyu。
方法一: 用圖像界面修改(永久性修改)
在終端輸入命令 nutui :[root@xiaolyu ~]# nmtui
進入如下圖形界面:
選擇第三行:Set system hostname
按回車鍵,進入:
然后直接進行編輯修改即可:
選中《OK>按回車鍵即可。
OK 即可!
重新打開一個新的終端,既可以發現主機名已經修改過來了:
[root@lyu ~]#
方法二:用命令行模式修改主機名:(永久修改,靜態模式)
比如這里講lyu改成xiaolyu:
[root@lyu ~]# hostnamectl
Static hostname: lyu
Icon name: computer-vm
Chassis: vm
Machine ID: 41395788ce5a4b3f93805203ebf82245
Boot ID: 02c90c2e76784d1293358ab6bc509f78
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
[root@lyu ~]# hostname --help
Usage: hostname [-b] {hostname|-F file} set host name (from file)
hostname [-a|-A|-d|-f|-i|-I|-s|-y] display formatted name
hostname display host name
{yp,nis,}domainname {nisdomain|-F file} set NIS domain name (from file)
{yp,nis,}domainname display NIS domain name
dnsdomainname display dns domain name
hostname -V|--version|-h|--help print info and exit
Program name:
{yp,nis,}domainname=hostname -y
dnsdomainname=hostname -d
Program options:
-a, --alias alias names
-A, --all-fqdns all long host names (FQDNs)
-b, --boot set default hostname if none available
-d, --domain DNS domain name
-f, --fqdn, --long long host name (FQDN)
-F, --file read host name or NIS domain name from given file
-i, --ip-address addresses for the host name
-I, --all-ip-addresses all addresses for the host
-s, --short short host name
-y, --yp, --nis NIS/YP domain name
Description:
This command can get or set the host name or the NIS domain name. You can
also get the DNS domain or the FQDN (fully qualified domain name).
Unless you are using bind or NIS for host lookups you can change the
FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
part of the FQDN) in the /etc/hosts file.
[root@lyu ~]# hostnamectl --static set-hostname xiaolyu
再次打開一個新終端,可以發現@后面的用戶名已經修改。
[root@lyu ~]# hostname
xiaolyu
[root@lyu ~]# hostnamectl
Static hostname: xiaolyu
Icon name: computer-vm
Chassis: vm
Machine ID: 41395788ce5a4b3f93805203ebf82245
Boot ID: 02c90c2e76784d1293358ab6bc509f78
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
[root@lyu ~]#
(init6或者reboot之后也可以,但是比較麻煩)。
而且是永久修改。
如何讓@后面顯示的主機名也跟着變呢?重啟! reboot或者init 6
再次查看:
搞定!
修改主機名的方法,還有很多,后續我會繼續補充