problem with hostname

NoOp glgxg at sbcglobal.net
Wed Jul 8 18:04:45 UTC 2009


On 07/06/2009 07:51 PM, pkaplan1 at comcast.net wrote:
> When I first set up my box the system prompt read: 
> 
> <username>@<hostname>:$ 
> 
> Recently it changed to : 
> 
> <username>@(none):$ 
> 
> When I need to invoke sudo I get: 
> 
> <username>@(none):~$ sudo <command> 
> sudo: unable to resolve host 
> sudo: unable to resolve host 
> sudo: unable to resolve host 
> sudo: unable to resolve host 
> [sudo] password for <username>: 
> 
> I can set the hostname with: 
> 
> sudo hostname <hostname> 
> 
> but the new hostname is not retained after reboot. 

It won't, see 'man hostname'
<quote>
SET NAME
       When  called  with one argument or with the --file option, the
commands set the host name or the NIS/YP domain name.  Note that this is
effective  only  until  the  next  reboot.  Edit /etc/hostname for
permanent change.
Note, that only the super-user can change the names.
</quote>

> 
> Shouldn't the following define my hostname? 
> 
> <username>@(none):~$ cat /etc/hosts 
> 127.0.0.1 localhost 
> 127.0.1.1 <hostname> 
...
> <username>@(none):~$ cat /etc/hostname 
> <hostname> 

The last should (/etc/hostname). If you look at 'cat
/etc/rcS.d/S02hostname.sh/ or 'cat /etc/init.d/hostname.sh' you will see
that it reads /etc/hostname for a value & if it does not find one it
will resort to localhost.

I tested by duplicating your /etc/hosts and then blanked out
/etc/hostname (removed my hostname from the file). Rebooted and now my
system shows as yours:

<username>@(none):~$

Changed it back & rebooted & now I'm showing:

<username>@<hostname>:~$

> 
> How can I restore <hostname> permanently? 

As Fred pointed out:
$ gksu gedit /etc/hostname
add the host name you wish in the file. Note: only the hostname, nothing
else. Reboot and check 'cat /etc/hostname' again before doing anything.

If /etc/hostname is blank, then perhaps your network manager is making
the change?

What version/flavour of Ubuntu are you using? What permissions are set
for /etc/hostname?
$ ls -l /etc/hostname
-rw-r--r-- 1 root root 6 2008-07-12 13:56 /etc/hostname
Also check your user privileges (System|Administration|<username>|User
Privileges - see if 'Administer the system' is checked.






More information about the ubuntu-users mailing list