How Do I Change My Ubuntu Host Name?

How Do I Change My Ubuntu Host Name?
Page content

On an Ubuntu system, the hostname is an important aspect of the successful running of the PC or server. Usually configured at install, the hostname can be found in many files and folders where it identifies your computer. Most commonly it can be found in the Terminal whenever you want to enter a command, in the form:

usernam[email protected]

You can confirm this by entering the hostname command in the Terminal – the resulting outcome should be something like this:

[email protected]:~$ hostname


[email protected]:~$

If you plan on connecting your Linux computer or server to a local network then the hostname will need to be used. As such, you might prefer to choose something a little more meaningful than myubuntubox, for instance.

Changing your system hostname is relatively simple, however the impact this can have on your computer or server and the wider network is potentially disruptive. As such a sudden, unplanned decision isn’t suitable unless you’re the sole user of the system and haven’t yet set it up as a network device to be accessed by other computers.

Reasons for Changing Your Hostname

Given the risks involved in changing your hostname, you need to have some pretty strong reasons for altering it. The most common reason is that the default hostname has been applied during the system setup, something that is very easy to do in error.

This isn’t the only reason, of course. You might have a naming convention established for all network devices for instance, so changing the hostname to meet this would be pretty important (particularly in a corporate environment). Alternatively, the device might be hosting websites, so having a hostname of “Ubuntu” might prove a little confusing for the webmaster, not to mention a potential security risk.

The Impact of a New Hostname

Using a new hostname on your Ubuntu Linux box should enable you to recognize your computer on a network, but there are various problems that this might cause. Notably, if your Ubuntu computer or server is being used for sharing files across a network, then an alteration to the hostname will render any shortcuts useless, so these will have to be setup again.

Note also that certain characters cannot be used in hostnames. As such, you should limit your chosen name to alphanumeric characters rather than symbols.

Probably the main issue however, is that the hostname might be present in other files found below the /etc directory. For instance, you might have some installed packages that use the original hostname, and finding and replacing the hostname across several folders might prove difficult.

Changing the hostname is simple enough, and can be done either in the GUI (graphical user interface) or via the command line in the Terminal.

Applying a New Host Name in the GUI

If you prefer to keep things simple, you can easily update the hostname in the GUI if you are using a version of Ubuntu prior to 10.04 without worrying too much about any other files and packages that might have been installed. In later versions you will need to open System > Administration > Synaptic Package Manager and search for gnome-network-admin. Mark this for installation and apply - you will then have the old menu available to you.

Updating the hostname in the GUI is done by opening System > Administration > Networking and altering the General > Host Settings > Hostname entry.

With this done, you will need to save the changes and restart your computer/server before the new hostname can take effect.

Note, however, that it is more common for this change to be made in the command line Terminal.

Configuring a New Ubuntu Hostname in the Terminal

Configuring a New Ubuntu Hostname in the Terminal

To change the hostname for your Ubuntu box in the Terminal, you will need to edit both /etc/hosts and /etc/hostname.

This is really simple to do via the Terminal, arguably simpler than via the GUI – simply open Applications > Accessories > Terminal and enter:

sudo /bin/hostname mynewhostname

(Note that you should be entering your own hostname).

You will also need to update the Hosts file with your new hostname, which can be launched using this command:

sudo edit /etc/hosts

With these changes applied, your new hostname will be available after a reboot. Remember you can check the new hostname has been correctly applied (or remind yourself what it is!) by typing hostname in the Terminal window.

Choosing the Right Host Name

Setting a new hostname is littered with potential pitfalls, particularly if you are changing the name of an established system that is currently in use. In a corporate environment, this could mean a loss of access to vital data for many users unless the change is carefully managed and the users informed beforehand.

Ultimately, choosing a useful and meaningful hostname when you first setup Ubuntu – thereby avoiding having to change the hostname later on – will allow you to avoid the risks described.


Author’s own experience.

Screenshot provided by author.