5

I'm using Lubuntu 12.04.

I was trying to change my computer name to "main" and I messed up, I'm not sure what to do now.

I was following the directions on this page.

Here's what I did:

sudo leafpad /etc/hostname

I changed the name, then stupidly closed the file, before changing "/etc/hosts"

Now when I try to move on to the next step (sudo leafpad /etc/hosts), or try any command that begins with "sudo" I get this error:

sudo: unable to resolve host main
No protocol specified
No protocol specified

I can see that the problem is that I've changed the hostname, so the computer's bewildered by my efforts to use sudo because now hostname and hosts don't match. All I need to do is change the name in hosts, but of course I can't do that without sudo.

Any ideas?

begtognen
  • 1,670
  • Your hostname is in your /etc/hosts file – wojox Jul 12 '13 at 12:44
  • /etc/hostname has a single line for me: vasa1-Inspiron-1545. Also, when using a GUI-editor, use gksudo or gksu, not sudo. –  Jul 12 '13 at 12:49
  • And /etc/hosts has, among other things: 127.0.1.1 vasa1-Inspiron-1545 –  Jul 12 '13 at 12:50
  • What do you mean by "Now when I try to do anything"? –  Jul 12 '13 at 12:52
  • I just googled for sudo: unable to resolve host main and got a lot of hits. I'm going through them! BTW, as I commented earlier, don't use sudo leafpad but gksudo leafpad despite what that blogger wrote! –  Jul 12 '13 at 13:05
  • I definitely will in the future, but for now gksudo gives me this error: "leafpad: Cannot open display: No protocol specified" – begtognen Jul 12 '13 at 13:13
  • 1
    Lekensteyn - Thanks so much. I don't know how to implement the solution in that question without the ability to use sudo, any ideas? – begtognen Jul 12 '13 at 13:36
  • 2
    Boot into a LiveUSB, mount your partition, and edit /etc/hosts. If you don't know the steps, tell us what's the output of mount | grep '/ ' – Alaa Ali Jul 12 '13 at 13:44
  • 1
    I appreciate your help, everyone. I tried this solution first and it worked beautifully:

    You should be able to fix it from the recovery console, you will need to remount the filesystem with rw permissions and then use a commandline editor e.g. after dropping to the root shell,

    Code:

    mount -o remount,rw /

    nano /etc/hosts

    and make your changes... Ctrl-o to save and Ctrl-x to quit

    – begtognen Jul 12 '13 at 14:20
  • Amc - Whoops, sorry about that. Done! (It says I can't accept my own answer for another 2 days, so I'll have to do that part later.) – begtognen Jul 12 '13 at 15:52

1 Answers1

8

SOLVED:

You should be able to fix it from the recovery console, you will need to remount the filesystem with rw permissions and then use a commandline editor e.g. after dropping to the root shell,

Code:

# mount -o remount,rw /
# nano /etc/hosts

and make your changes... Ctrl-o to save and Ctrl-x to quit

begtognen
  • 1,670