21

I would like to change my "Device name" as shown in the settings panel. How do I do this?

enter image description here

Anwar
  • 75,875
  • 31
  • 191
  • 309
Victor S
  • 692
  • 2
  • 7
  • 19

5 Answers5

28

Execute the following command using a terminal:

sudo sed -i 's/present-host-name/new-host-name/' /etc/hosts
sudo sed -i 's/present-host-name/new-host-name/' /etc/hostname

You can check your present-host-name by cat /etc/hostname or hostname.

Then reboot the computer, to see the changes.

vine_user
  • 2,741
  • 3
  • 23
  • 26
10
  • Open a terminal and issue the command

    gksu gedit /etc/hosts
    
  • Then change the line

    127.0.1.1   victor-System-Product-Name
    

    with

     127.0.1.1    your-desired-name
    
  • Then also open the file /etc/hostname with command gksu gedit /etc/hostname and change the hostname there to reflect the new name.

  • Then reboot the computer, to see the changes

Anwar
  • 75,875
  • 31
  • 191
  • 309
4

You can use the built in service hostnamectl

sudo hostnamectl set-hostname [NEW-HOSTNAME]

replacing [NEW-HOSTNAME] with the hostname you would like this should work immediately on most things but I would reboot for good measure.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Ember
  • 161
  • 4
2

Since there are plenty of ways to get something done here is one more:

While in your root directory:

cd /etc
sudo vi hostname  

Type in your admin password, press Enter.

Press i to 'insert' and change existing device name to the desired device name.

Press Esc and type :wq!, press Enter.

Restart the system for the change to take affect.

Seth
  • 57,282
  • 43
  • 144
  • 200
0

Run this command , it will open up Text editor

sudo gedit /etc/hostname 

Replace the present name to your Desired name. Save and close. Reboot for it to take effect.

atenz
  • 12,674
  • 5
  • 44
  • 66
  • Only changing the hostname, causes error to be shown on each sudo command to the terminal – Anwar Jul 06 '12 at 03:30
  • Thanks for noticing me about that , can you post the exact errors you see . According to [Hostname man page](http://manpages.ubuntu.com/manpages/precise/en/man1/hostname.1.html) **`Edit /etc/hostname for permanent change`**, even i tried this method and haven't encountered any such errors. – atenz Jul 06 '12 at 05:19
  • I edited `/etc/hostname` to a new name `anwar` from previous one `anwar-precise`. The error after rebooting the system and executing a sudo command is `sudo: unable to resolve host anwar`. It may be only warning. I executed `sudo gedit` command – Anwar Jul 06 '12 at 05:32
  • I searched for these and concluded you need to change both `hosts` and `hostname` to reflect complete changes , depending on maybe loopback , DNS , domain-name, resolv.conf. But its better to do changes in both of them. Yet i haven't encountered any such `error` ,must be different interface. – atenz Jul 06 '12 at 06:00