http://blog.csdn.net/ruglcc/article/details/7802077
1、查看主機(jī)名
在Ubuntu系統(tǒng)中,快速查看主機(jī)名有多種方法:
其一,打開一個(gè)GNOME終端窗口,在命令提示符中可以看到主機(jī)名,主機(jī)名通常位于“@”符號后;
其二,在終端窗口中輸入命令:hostname或uname –n,均可以查看到當(dāng)前主機(jī)的主機(jī)名。
2、臨時(shí)修改主機(jī)名
命令行下運(yùn)行命令:“hostname 新主機(jī)名”
其中“新主機(jī)名”可以用任何合法字符串來表示。不過采用這種方式,新主機(jī)名并不保存在系統(tǒng)中,重啟系統(tǒng)后主機(jī)名將恢復(fù)為原先的主機(jī)名稱。
例子:hostname ubuntu-temp
這樣主機(jī)名字就臨時(shí)被修改為ubuntu-temp,但是終端下不會立即顯示生效后的主機(jī)名,重開一個(gè)終端窗口(通過ssh連接的終端需要重新連接才可以);
3、永久修改主機(jī)名
在Ubuntu系統(tǒng)中永久修改主機(jī)名也比較簡單。主機(jī)名存放在/etc/hostname文件中,修改主機(jī)名時(shí),編輯hostname文件,在文件中輸入新的主機(jī)名并保存該文件即可。重啟系統(tǒng)后,參照上面介紹的快速查看主機(jī)名的辦法來確認(rèn)主機(jī)名有沒有修改成功。
值的指出的是,在其它Linux發(fā)行版中,并非都存在/etc/hostname文件。如Fedora發(fā)行版將主機(jī)名存放在/etc/sysconfig/network文件中。所以,修改主機(jī)名時(shí)應(yīng)注意區(qū)分是哪種Linux發(fā)行版。
3、/etc/hostname與/etc/hosts的區(qū)別
/etc/hostname中存放的是主機(jī)名,hostname文件的一個(gè)例子:
v-jiwan-ubuntu-temp
/etc/hosts存放的是域名與ip的對應(yīng)關(guān)系,域名與主機(jī)名沒有任何關(guān)系,你可以為任何一個(gè)IP指定任意一個(gè)名字,hostname文件的一個(gè)例子:
127.0.0.1? ?? ? localhost
127.0.1.1? ?? ? v-jiwan-ubuntu
?
1.癥狀:
當(dāng)你是使用sudo來執(zhí)行命令時(shí),總是在命令執(zhí)行時(shí),首先輸出:“sudo:unable to resolve host Lily-desktop”(假設(shè)Lily-desktop 是你的當(dāng)前主機(jī)的名字(host-name)), 但是怎樣才能使使用sudo像以前一樣不錯(cuò)誤提示,正常工作呢。
?
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.產(chǎn)生該癥狀的原因:
這種癥狀經(jīng)常發(fā)生在更改了hostname的情形下。在通過 編輯? /etc/hostname 改變了主機(jī)名字(hostname)之后, 我們還需要改變 /etc/hosts文件的相應(yīng)部分的內(nèi)容
?
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): //使粗體字對應(yīng)的詞與當(dāng)前的主機(jī)名即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
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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