3

Can someone tell me how to change the computer name on a pc, I've tried to edit the /etc/hostname file but it won't allow me access to save the amended file, thought the user the system created was the administrator obviously not.

Thanks

1
  • Run in a Terminal: sudo nano /etc/hostname when asked enter your password, then edit the displayed text.
    – koni_raid
    May 9, 2013 at 12:25

2 Answers 2

7

Changing the hostname or computer name in ubuntu

Edit /etc/hostname and change to the new value, for example name we are using hostname Ubuntu

sudo nano /etc/hostname
Ubuntu    

Edit /etc/hosts and change the old 127.0.1.1 line to your new hostname

127.0.0.1   localhost
127.0.1.1   ubuntu.local    ubuntu   # change to your new hostname/fqdn

Note : Edit /etc/hosts and change the old 127.0.1.1 line to your new hostname (if you dont do this, you wont be able to use sudo anymore. If you hav e already done it, press ESC on the grub menu, choose recovery, and edit your host file to the correct settings)

Now after a reboot, your hostname will be the new one you chose

If you want to apply the change without a reboot,

sudo service hostname restart

OR

 sudo /etc/init.d/hostname restart

Note : Above command to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname).

4

You need to change 2 files and can use the following commands for that...

pkexec nano /etc/hostname
pkexec nano /etc/hosts

Only change the name; nothing else.

2
  • says cannot open display?
    – Belstead54
    May 9, 2013 at 12:32
  • Are you using ssh to connect to the system? That message means that there is no X server active(?)
    – Rinzwind
    May 9, 2013 at 12:35

Not the answer you're looking for? Browse other questions tagged .