RSS

How to change the hostname in Ubuntu

03 Aug

I have often built a new desktop or server without giving much thought to the hostname I should use. I then become too lazy to ever change it later, leaving it set to something unhelpful or inappropriate for the purposes of deployment.

Thankfully it’s very easy to change your server hostname in Ubuntu, and across all other Linux distributions in general. It’s as simple as issuing a couple of commands via a command line interface, editing two files, and then a quick reboot to puts the changes into action. So there’s no real excuse not to right your previous wrong.

Let’s get started.

First up, let’s edit the ‘hostname’ file replacing the existing entry with our new hostname:

nano -w /etc/hostname

Next up, edit the ‘hosts’ file replacing the old hostname with the new:

nano -w /etc/hosts

You can reboot your machine immediately for the new hostname to take effect. Or alternatively, just issue the following command line to implement the hostname changes without a restart:

sudo /etc/init.d/hostname.sh start

Others may prefer to substitute “nano -w” with their preferred command line text editing tool. I’ve been using Pico/Nano since Cobalt RaQ server days, and I’ve never grown out of the habit.

About these ads
 
Leave a comment

Posted by on August 3, 2012 in How to, Linux

 

Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: