Debian Admin - Your way to Debian World

September 17, 2006

Change hostname or Server name of a Linux Machine

by @ 11:50 am. Filed under Network

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Checking your Linux host name

First, see if your host name is set correclty using the following commands:

#uname -n
#hostname -a
#hostname -s
#hostname -d
#hostname -f
#hostname

If the above commands return correctly with no errors then all may be well; however, you may want to read on to verify that all settings are correct.

Normally we will set the hostname of a system during the installation process.

Change the hostname on a running Linux system

On any Linux system you can change its hostname with the command ‘hostname‘.

#hostname

without any parameter it will output the current hostname of the system.

#hostname –fqd

it will output the fully qualified domain name (or FQDN) of the system.

#hostname NEW_NAME

will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations - see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.

Permanent hostname change on Debian based Linux systems

Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh

#cat /etc/hostname

debianadmin

So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run

/etc/init.d/hostname.sh startto make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).

If you want more details check hostname man page

Use sysctl to change the hostname

use sysctl to change the variable kernel.hostname:

Use:

#sysctl kernel.hostname

to read the current hostname, and

#sysctl kernel.hostname=NEW_HOSTNAME

to change it.

If you want more details check sysctl man page

You can use the same process for all debian based distributions and other linux machines

also.

Tags: , , ,

You may also be interested in...

6 Responses to “Change hostname or Server name of a Linux Machine”

  1. debian-admin Says:

    Shouldn’t that be:
    hostname –fqdn ?

    (or hostname -f).

  2. Ricky Says:

    Thanks… very useful information.

  3. jam Says:

    hostname -fqd didn’t work…
    I think it should jsut be hostname -f ?

    I may be wrong though..
    But thanks :D

    JAM

  4. cmos Says:

    I think that should be hostname –fqdn

  5. platypusjh Says:

    Nope. It’s “hostname –fqdn” or “hostname -f”

    Sorry, couldn’t resist since everyone else was nitpicking. :)

    Thanks for the excellent article. Worked like a charm!

  6. Sean Says:

    My question is should you put the whole FQDN in the hostname file for a permanent change, or just the hostname itself?

Leave a Reply

Subscribe RSS Feed

subscribe to the Debian Admin RSS feed

Internal links:

Sponsors:



Categories:

Support Debian Admin

Amount $:
Website(Optional):

Sponsors:

Archives:

Related Links:


Favourite Sites:

Wordpress Collection
Windows Reference
Ubuntu Geek
DebianHelp
All About Debian Tutorials
Power Electrical
Check Your IP Here
Debian,Ubuntu News
DebCentral
Tuxmachines
Capnkirby
Libervis
Nuxifield
Linux Horizon
Linux Appfinder
Debuntu
GNU/Linux For Everyone
Free Penguin
DebianAdmin is not related to the Debian Project.
This site is copyright © 2006,2007 Debian Admin
All Trademarks are the property of their respective owners.
The contents of this website may not be mirrored or archived without the express written permission of DebianAdmin Site Owner.

DISCLAIMER: All the information, troubleshooting methods, utilities offered in this website is provided AS-IS, without any warranties. Though I strive for perfection, and always test the validity and effectiveness of the troubleshooting content in various systems, I assume no responsibility for your use of these Fixes, Utilities and other troubleshooting advice. The author will not be liable for any special, incidental, consequential or indirect damages due to loss of data or any other reason. All use is completely at your own risk. Changes to the existing content and new additions are made to this website periodically, without notification.
Rodney's Kontera DynamiContext Plugin plugged in.