Hints and Tips Topic
   >  Changing the Hostname
   >  Finding your IP & Mac Address
   >  Creating Users and Groups
   >  Running Scripts at Startup
   >  Network Interface Configuration
   >  Changing the Grub Default Option

 

How to Change the Hostname on your Linux Computer

What is the Hostname and why would I want to change it?

In Linux, the hostname is just a friendly name (-i.e. text string that is hopefully somewhat more obvious that the IP Address) that can be used to reference your computer. It is only really of much import if you have remote machines/services/users that need to connect to your machine and which cannot easily use the IP Address (-e.g. because DHCP assigns a different one each time you boot, for example).

[The hostname] is only really of much import if you have remote machines/services/users that need to connect to your machine and which cannot easily use the IP Address ..

You can print out your system's hostname using the hostname command:

$ hostname 
myMachine

Some Linux variants (-like Ubuntu) also set the command line prompt to the following format:

<username>@<hostname>

For example:

fredb@myMachine:~$

How to Change the Hostname Temporarily

If you just want to change your computer's hostname for the current session (-i.e. until the next reboot), then you can use the hostname command to do this:

$ hostname
myMachine
$ hostname myServer
$ hostname
myServer

In the example above, as soon as the machine is rebooted the hostname will revert back to "myMachine:


How to Change the Hostname Permanently

If want to change your computer's hostname permanently, then you need to edit the /etc/hostname file, for example:

$ sudo vi /etc/hostname

The current value of your hostname should be displayed:

myhost

Simply change the text to the hostname desired and save your changes.

Note: changes to the /etc/hostname file will not take effect until you reboot the machine

Note: like all system administration functions, you'll need to use the sudo command to assume root before making any of the above changes


HomeSite IndexDesktop GuideServer GuideHints and TipsHardware CornerVideo SectionContact Us

 sitelock verified Firefox Download Button