Linux修改主機名稱


碰到這個問題的時候,是在安裝Zookeeper集群的時候,碰到如下問題

java.net.UnknownHostException: XXXX Name or service not known
java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) 
............

這里猜想到是主機的地址沒有配對,網上給了方案是重新設置linux的主機名。

 

Step1:查看當前的主機名

[root@sxl133 Desktop]# hostname sxl133

這里的主機名是sxl133,如果沒有設置,則是localhost.localdomain,這是linux默認的主機名。

 

Step2:更新network文件

[root@sxl133 Desktop]# vi /etc/sysconfig/network [root@sxl133 Desktop]# 

將HOSTNAME=localhost.localdomain改成sxl133(我們想要設置的主機名)

退出編輯。

 

Step3:更新hosts文件

輸入:vi /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

改成

127.0.0.1 localhost sxl133 localhost4 localhost4.localdomain4 ::1         localhost sxl133 localhost6 localhost6.localdomain6

退出編輯。

 

Step4:reboot重啟服務器,同時查詢主機名

1 [root@sxl133 Desktop]# reboot 2 [root@sxl133 Desktop]#  hostname

 

參考文檔

https://jingyan.baidu.com/article/574c52192a1d8d6c8d9dc1ce.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM