天天看點

sudo: unable to resolve host zz: Connection timed out

當使用sudo時會出現 sudo: unable to resolve host zz: Connection timed out這樣的提示。

zz@zz:~/work$ fdisk -l
fdisk: cannot open /dev/sda: Permission denied
zz@zz:~/work$ sudo fdisk -l
sudo: unable to resolve host zz: Connection timed out
[sudo] password for zz: 
Disk /dev/sda:  GiB,  bytes,  sectors
Units: sectors of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disklabel type: dos
Disk identifier: 

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *             G  Linux
/dev/sda2          G   Extended
/dev/sda5             G  Linux swap / Solaris
/dev/sda6          G  Linux


zz@zz:~/work$ vi /etc/hostname 
           

主要原因是我裝完ubuntu後手賤,修改了hostname,修改的方法是在about computer的ui界面直接修改的,而不是在配置檔案中修改。結果出現了timeout的提示。

經過網上的查找發現,影響hostname的地方主要有下面的2個地方:

1. /etc/hostname
2. /etc/hosts
           

依次檢視了這2個檔案,/etc/hostname是正确的,已經是修改後的主機名。

但是/etc/hosts中的主機名仍然是修改前的主機名。這個檔案内容的形式如下:

..    localhost.localdomain localhost
 .    my-machine
           

把my-machine修改為實際的主機名之後,就沒有Connection timed out的問題了。

寫到這裡突然發現這篇文章好水。。。

繼續閱讀