Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I connect to my server (ubuntu server 10.10), I get this:

name@server-name.belkin ~>

How can I remove ".belkin"?

share|improve this question
Try editing /etc/ hosts. gksudo gedit /etc/hosts and replace server-name.belkin by whatever name you desire. – LFC_fan Oct 26 '10 at 8:39
Do you want to change the actual server name, or just the way it's displayed in the prompt? – Dave Jennings Oct 26 '10 at 18:07

13 Answers 13

up vote 270 down vote accepted

You need to edit the computer name in two files:




These will both need administrative access, so run

gksu gedit /path/to/file

Simply replace any instances of the existing computer name with your new one. When complete run sudo service hostname restart or restart your computer and the name will have been changed.

See also:

share|improve this answer
After that, just sudo service hostname restart and the hostname has been changed without rebooting. – Anthony O. Nov 20 '13 at 0:37
In Ubuntu 14.04 there is no service 'hostname'. What can I do there to avoid reboot. – Arpad Horvath Jul 28 '14 at 6:39
sudo service hostname restart doesn't work on default install of ubuntu server 14.04 on AWS. I had to do full server restart – gerrytan Oct 30 '14 at 21:47
On 14.04, I simply ran sudo hostname, and that did the trick. I didn't notice any immediate change, but when I opened a new terminal, I saw my hostname had indeed changed. – TSJNachos117 Nov 22 '14 at 8:33
sudo hostname new-host-name worked for me on ubuntu 13.10 – Lekhnath Jan 14 '15 at 12:04

It's quite easy:

  1. Edit /etc/hostname, make the name change, save the file.

  2. You should also make the same changes in /etc/hosts file

  3. Run sudo /etc/init.d/hostname restart or sudo service hostname restart

As long as you have no application settings depending on the 'old' hostname, you should be ok ;-)

share|improve this answer
WARNING: If you do this without changing /etc/hosts accordingly you will be unable to use sudo because your hostname will fail to lookup – João Pinto Dec 6 '10 at 16:10
You're right regarding editing the /etc/hosts, i forgot about it (just added it to my answer), though sudo seems to be working fine for me without changing it (i've restarted the machine and it still works) – Pavlos G. Dec 6 '10 at 16:14
I don't have any reference to my hostname (new or old) in /etc/hosts, only localhost and some IPv6 rules. – Oli Dec 9 '10 at 9:30
networkmanager adds it, at least that happens in my machine. – Pavlos G. Dec 9 '10 at 10:30
Note: this will not work for ubuntu 14.x, as hostname is no longer in init.d – Rápli András Oct 9 '14 at 11:42

It is safe to do, you just need to be sure you edit both the system hostname configuration file (/etc/hostname) and the hostname name resolution file (/etc/hosts). From a terminal execute the following:

sudo -s
editor /etc/hostname
editor /etc/hosts
shutdown -ry now
share|improve this answer
You can avoid shutdown with sudo service hostname restart. – Wtower Nov 19 '14 at 12:27
@Wtower Doesn't work with 14.04. :( – dotslash Jan 2 at 6:13

In addition to editing /etc/hosts and /etc/hostname, various services might have issues with the change as well. Mysql and postfix are installed by default in ubuntu. A broken postfix won't affect most ubuntu users, since it's a background email server that isn't used by much.


sudo editor /etc/postfix/
sudo service postfix restart

The default config for mysql doesn't use hostname, so it will work fine as-is. If you have customized it, edit the files in /etc/mysql/ and restart the service.

You may also want to edit /etc/motd (message of the day), which is shown on virtual terminals and remote logins. That one won't harm anything though.

Other services that you may have installed that would need fixing are apache, bind9, etc. In each case, find and edit the hostname in their config and restart the service.

share|improve this answer

Another better and safe way to rename hostname

Install ailurus

  • Add the PPA and update your repository

    sudo add-apt-repository ppa:ailurus && sudo apt-get update

  • Install ailurus

    sudo apt-get install ailurus

  • After installation it will be found under Applications>>System Tools>>Ailurus
    alt text
share|improve this answer
Why is this getting negative votes? Should be better to configure something with a dedicated tool than muck around on the command line and break things in the process. – endolith Jan 20 '11 at 3:49
Installing such a big software just to change a hostname is a bit of an overkill – Abhay Rana Jun 17 '11 at 1:56
I agree that this is overkill -- in particular because the software not available in the repositories but has to be installed from a PPA... – Marcel Stimberg Jul 5 '11 at 16:55
@karthick87 perhaps mention in your answer that this is a large piece of software (with other configuration options)? - personally I agree with endolith that a tool with a single, simple change point is better than lots of command line operations (I use Ubuntu Tweak, also currently available from a PPA) – d3vid Oct 14 '11 at 7:19
I think that you can break a lot more things (and more easily) using this tool, than just replacing a word in a couple of files. It exposed too many things to you. – gerlos Jan 20 at 18:53

hostnamectl is the best way if you have systemd (13.10 onwards):

hostnamectl set-hostname 'new-hostname'


  • does not require rebooting
  • persists after reboots

More info at:

share|improve this answer
works perfect in Ubuntu 15.10 – A.B. Feb 26 at 13:28
Doesn't change /etc/hosts in 14.04 – Sandeep Datta Jul 1 at 15:37
@SandeepDatta thanks for feedback. Were you expecting that to be changed? I'm not sure how it works, but when I tested it the effect was permanent after reboot. – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Jul 1 at 15:58

The host name uniquely identifies your computer on the local network (and possibly on the Internet as well) so it's not a good idea to change it unless you know what you are doing.

But you can change the shell prompt not to display the .belkin (domain name part):

export PS1='\u@\h \w> '

See the bash man page and specifically the section on prompting for more information.

share|improve this answer

Use the hostname command to change your hostname

sudo hostname newname

However, this does not edit your hosts file, which you must do so as to make sure that your computer recognizes itself

gksudo /etc/hosts

And add a new entry for your hostname pointing to oldname newname

You could remove the old entry as well, but I prefer to keep it there.

share|improve this answer

If you don't want to play with a text editor, Ubuntu Tweak (grab the deb from their website) has that as one of the little things you can play with (along with lots of other little tweaks that you might want to make but don't really want to play around with the terminal and the files themselves).

share|improve this answer
Out of curiosity, is there any particular reason why Ubuntu Tweak is not in the software repos? – Olivier Lalonde Dec 7 '10 at 22:31
They never got around to adding it/haven't been accepted. You can add their repo to your list either right after starting tweak or through the terminal/repo list. – dkuntz2 Dec 7 '10 at 23:40
You can also add Ubuntu Tweak as a PPA with sudo add-apt-repository ppa:tualatrix/ppa then sudo apt-get update then sudo apt-get install ubuntu-tweak – d3vid Oct 14 '11 at 7:15
note that since ~13.04 Ubuntu Tweak no longer provides this option – d3vid Jun 15 '14 at 11:32

The following command change the hostname on the fly but to make it permanent, you have to edit /etc/hostname:

    echo 'new_hostname' > /proc/sys/kernel/hostname

Open a new terminal session and you'll see it right away.

With systemd in place, the proper way to do it is -> hostnamectl set-hostname "new_name".

share|improve this answer

If you want a GUI assisted process install Ubuntu-Tweak. Among other uses of this app is the ability to change computer name through tab "Computer-Details" -> "Hostname"

share|improve this answer

Open a terminal and

sudo sed -i '1s/.*/desired-name/g' /etc/hostname

# you need restart to effect with...

sudo shutdown -r 0
share|improve this answer

I know I'm late to the game, but the punctuation is really limited. The one that caught me out was NO UNDERSCORES.

The Internet standards (Requests for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.

share|improve this answer
Although your answer is 100% correct, it might also become 100% useless if that link is moved, changed, merged into another one or the main site just disappears... :-( Therefore, please edit your answer, and copy the relevant steps from the link into your answer, thereby guaranteeing your answer for 100% of the lifetime of this site! ;-) You can always leave the link in at the bottom of your answer as a source for your material.. – Ravan Sep 7 '15 at 1:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.