change host name and hit the wall :(

Asked by Bob

Like a fool, I tried to do what was sad on a page and the unclear instructions have me beating my head. on my desk.

What I did.
Type the following command to edit /etc/hostname using nano or vi text editor:
sudo vi /etc/hostname
Delete the old name and setup new name.

that is as far as I got because after that is read and save. I do not know how to save there is not save on the menu at the bottom. How to save I have no clue,

now I'm stuck. when I go back, I get this.

E325: ATTENTION
Found a swap file by the name "/etc/.hostname.swp"
          owned by: root dated: Fri Jul 5 22:18:59 2019
         file name: /etc/hostname
          modified: YES
         user name: root host name: rjsmith-desktop
        process ID: 4288
         [not usable on this computer]
While opening file "/etc/hostname"
             dated: Sun Aug 7 03:56:21 2016

(1) Another program may be editing the same file. If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes. Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /etc/hostname"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/etc/.hostname.swp"
    to avoid this message.
"/etc/hostname" 1 line, 16 characters
Press ENTER or type command to continue

How I got here. I had to clone my hard-drive from one computer to use in computer 2. and to get them to work together I can't have the same hostname. So I was going to change it. That is all I need. 6 hours later and Im even more lost and wondering.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bob (smith13) said :
#1

I just read go back to where you where aka the warning page? That is where I was
it reads just click R to recover or Q to quit. That was a laugh I tried both, and it goes to the thing where I only see the old username but I can't do or type anything on it. :(

Revision history for this message
Manfred Hampl (m-hampl) said :
#2

When you type the command
cat /etc/hostname
does it still show the old hostname?

If yes, then the whole editing attempt has failed, but has created an editor temp file.
I suggest that you do the following:

1. Delete the "temporary swap" file from the previous editor session by issuing the command
sudo rm /etc/.hostname.swp

2. Use a different editor that probably is easier to use than vi, either
sudo gedit /etc/hostname
or
sudo nano /etc/hostname
and change the hostname as originally planned.

Revision history for this message
Bob (smith13) said :
#3

rjsmith@hermann:~$ sudo rm /etc/.hostname.swp
sudo: unable to resolve host hermann: No such file or directory
rm: cannot remove '/etc/.hostname.swp': No such file or directory

as you can see my hostname is now a mix of the old and new name with an @ in the middle. I don't know what the @ is doing or if it's doing nothing and is just part of the name now? Or is that my host name after the @ and I did it right? I've over read to much bad info and I'm lost. lol

Two things that may or may not result from this. I've got Synergy working Yeah! but the placement on the Synergy setting is backwards. The computer that is set to be on top, is set below. But it working as if it's on the top and I really don't care because it's working.

2. I can't get Pidgin messenger to work and I think it's the hostname I original had "Hermann", not hermann as it is now. You never realize how handy something is till you lost it and the phone never stops ringing. lol

ok so I need to know what is @ ? Is that my hostname after the @ Did do it? or is it the hold thing?

and if I got it, do you happen to know if I need to change the host name on Pidgin and where that would be?

Sorry if I'm asking to much but are time zones are 1/2 an earth apart and the next day delay to see what you said suck.

Revision history for this message
Bob (smith13) said :
#4

Please read #3 first^

I was pecking around and found this on nano

127.0.0.1 localhost
127.0.1.1 rjsmith-desktop << that is the old host name :(

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

I've got a screen name, a computer name, a hostname and now a local host name?
Are there two kinds of hostnames?? also I'm on 16.4 don't know if that matters.

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

1. "computername" and "hostname" are synonyms.

2. When you open a terminal window, you usually see a prompt that consists of your username, the @ sign, the hostname, the : sign, the current directory and finally a $ sign
In comment #3 it shows
rjsmith@hermann:~$
which is
rjsmith - being the username of the person logged in
@ - a constant string as separator
hermann - the hostname of your system (attention - not present in /etc/hosts which is a problem)
: - a constant string as separator
~ - shortcut name for your home Directory
$ - a constant string as separator

Apparently currently some programs beleive that the hostname of your system should be "hermann", but /etc/hostname still states that it is rjsmith-desktop

Please provide the output that you receive for the commands

cat /etc/hostname
cat /etc/hosts

To avoid losing more time due to time differences, you could try the following commands based on http://ubuntuhandbook.org/index.php/2014/04/change-hostname-ubuntu1404/ (not verified whether it really works, but I do not want to misconfigure my system)

hostname rjsmith-desktop
sudo gedit /etc/hostname /etc/hosts
in the editor in both tabs that you see change rjsmith-desktop to hermann (or whatever the new computer name should be), save the files, close the editor and then reboot.

Revision history for this message
Bob (smith13) said :
#6

rjsmith@hermann:~$ cat /etc/hostname
hermann
rjsmith@hermann:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 rjsmith-desktop

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

rjsmith@hermann:~$ sudo gedit /etc/hostname /etc/hosts
sudo: unable to resolve host hermann: No such file or directory
[sudo] password for rjsmith:
No protocol specified
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused

(gedit:12543): Gtk-WARNING **: cannot open display: :0

Revision history for this message
Manfred Hampl (m-hampl) said :
#7

Did you try running the command

hostname rjsmith-desktop

befor the "sudo gedit ..." command?

Revision history for this message
Bob (smith13) said :
#8

add on for #6^

rjsmith@hermann:~$ hostname hermann
hostname: you must be root to change the host name
rjsmith@hermann:~$

I tried the first thing from the page you sent and it back to an old problem. I'm not root. I've forgotten how many time that has happened. one day I'm root and the next I'm not??

Revision history for this message
Bob (smith13) said :
#9

Yes

rjsmith@hermann:~$ hostname rjsmith-desktop
hostname: you must be root to change the host name

Revision history for this message
Manfred Hampl (m-hampl) said :
#10

Try

sudo hostname rjsmith-desktop
sudo gedit /etc/hostname /etc/hosts

and report whether this works.

If this does not work, then you have to reboot in recovery mode and try editing the /etc/hosts and /etc/hostname files from a root command prompt. I will provide a 'how-to' if necessary.

Revision history for this message
Bob (smith13) said :
#11

rjsmith@hermann:~$ sudo hostname rjsmith-desktop
sudo: unable to resolve host hermann: No such file or directory
[sudo] password for rjsmith:
rjsmith@hermann:~$ sudo gedit /etc/hostname /etc/hosts
Invalid MIT-MAGIC-COOKIE-1 keyFailed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused

(gedit:25941): Gtk-WARNING **: cannot open display: :0

I was thinking if I cloning the hard drive again. It only takes around five to ten minutes to do. They pop out really easy and I have an ineo cloning dock. Then if you could give me a detailed how to change the hostname the right way in both places. lol. So I can get both places right the first time and not lock myself out. I have all my files on a 3ed and 4th hard-drive so I will lose nothing. and knowing I got 1/2 of it right will help and I think it would be easier all around. I don't know if your suggestion is easier than what I'm thinking. What do you think? I say Pick the easy road and will try that. :)

But first I've got to get some sleep I'm not doing anything with a tired brain. I'll see what you say when I wake sometime in your afternoon or evening. :) and after a cup of coffee I will try what you write.

Revision history for this message
Manfred Hampl (m-hampl) said :
#12

sudo seems to work, although it is complaining "unable to resolve host"
Apparently gedit does not work in the current situation, so I recommend using a different editor:

sudo nano /etc/hosts

Change the second line such that it contains both usernames

127.0.1.1 rjsmith-desktop hermann

then save the file (ctrl-o) and exit the editor (ctrl-x)

Finally reboot and check whether the system is working again.

Revision history for this message
Manfred Hampl (m-hampl) said :
#13

oops, typo error, must of course read

... that it contains both host names

Can you help with this problem?

Provide an answer of your own, or ask Bob for more information if necessary.

To post a message you must log in.