2

The hostname of my name is very long, which is odd. How can change the hostname for my system?

My hostname, currently, is

himanshu@himanshu-Lenovo-ideapad-100-15IBD:~$

Is there any way I can shorten this or change it entirely?

muru
  • 197,895
  • 55
  • 485
  • 740
  • First, check the linked question and, second, if this is a clean installation, a simple fix would be to just reinstall it and change the hostname that is filled in after you enter your name while Ubuntu is installing. As for an easier fix, I don't know. – Amolith Oct 11 '17 at 18:24

1 Answers1

7

Open Terminal (Alt+Ctrl+T), and enter this:

sudo -H gedit /etc/hostname

Enter your password, and then a file will open. Just change the name to the new hostname, and save the file. Do the same with the hosts file, by running:

sudo -H gedit /etc/hosts

Edit the name to your new hostname after 127.0.0.1 and save.

Restart your computer, and it should be done.

Edit: Use gksudo instead of sudo. It's safer.

  • At all sudo gedit or sudo <any GUY application> is not a good idea. This will change the ownership of some files and folder within your home directory, that will cause future errors. To recover from this problem you should run sudo chown -R $USER:$USER $HOME. For future use sudo -i gedit, or sudo -H gedit, or better sudo nano filename. – pa4080 Oct 11 '17 at 19:44
  • 2
    sudo -e filename – user334639 Oct 12 '17 at 00:23
  • @pa4080 I did not have knowledge of that. Learned something new. Thank You. – Kartik Shah Oct 12 '17 at 15:16
  • Use gksudo it is much safer than sudo Ex : gksudo gedit filename – himanshuxd Nov 25 '17 at 22:02