http://blog.csdn.net/ruglcc/article/details/7802077
1、查看主機名
在Ubuntu系統中,快速查看主機名有多種方法:
其一,打開一個GNOME終端窗口,在命令提示符中可以看到主機名,主機名通常位于“@”符號后;
其二,在終端窗口中輸入命令:hostname或uname –n,均可以查看到當前主機的主機名。
2、臨時修改主機名
命令行下運行命令:“hostname 新主機名”
其中“新主機名”可以用任何合法字符串來表示。不過采用這種方式,新主機名并不保存在系統中,重啟系統后主機名將恢復為原先的主機名稱。
例子:hostname ubuntu-temp
這樣主機名字就臨時被修改為ubuntu-temp,但是終端下不會立即顯示生效后的主機名,重開一個終端窗口(通過ssh連接的終端需要重新連接才可以);
3、永久修改主機名
在Ubuntu系統中永久修改主機名也比較簡單。主機名存放在/etc/hostname文件中,修改主機名時,編輯hostname文件,在文件中輸入新的主機名并保存該文件即可。重啟系統后,參照上面介紹的快速查看主機名的辦法來確認主機名有沒有修改成功。
值的指出的是,在其它Linux發行版中,并非都存在/etc/hostname文件。如Fedora發行版將主機名存放在/etc/sysconfig/network文件中。所以,修改主機名時應注意區分是哪種Linux發行版。
3、/etc/hostname與/etc/hosts的區別
/etc/hostname中存放的是主機名,hostname文件的一個例子:
v-jiwan-ubuntu-temp
/etc/hosts存放的是域名與ip的對應關系,域名與主機名沒有任何關系,你可以為任何一個IP指定任意一個名字,hostname文件的一個例子:
127.0.0.1? ?? ? localhost
127.0.1.1? ?? ? v-jiwan-ubuntu
?
1.癥狀:
當你是使用sudo來執行命令時,總是在命令執行時,首先輸出:“sudo:unable to resolve host Lily-desktop”(假設Lily-desktop 是你的當前主機的名字(host-name)), 但是怎樣才能使使用sudo像以前一樣不錯誤提示,正常工作呢。
?
when you’re running commands with?
sudo
?at beginning.It outputs “sudo:unable to resolve host Lily-desktop”(here assume current host-name is Lily-desktop),however the commands work as well as before.
?
?
2.產生該癥狀的原因:
這種癥狀經常發生在更改了hostname的情形下。在通過 編輯? /etc/hostname 改變了主機名字(hostname)之后, 我們還需要改變 /etc/hosts文件的相應部分的內容
?
This always happens after host-name changed.After change host-name by edit? /etc/hostname ,we also need to do a change in? /etc/hosts ?file.
?
3.解決方案:
Solve:
Edit /etc/hosts:?? // 編輯? /etc/hosts 文件
gksudo gedit /etc/hosts
make it looks like (change boldfaced words to current host-name): //使粗體字對應的詞與當前的主機名即hostname 一致
127.0.0.1 localhost 127.0.1.1 Lily-desktop # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
