Showing posts with label hostname. Show all posts
Showing posts with label hostname. Show all posts

Friday, January 15, 2016

How to change hostname in Red Hat 6 ?

There are several ways to change the hostname of a machine running Redhat 6.  These also works on CentOS, Fedora and older/other Redhat variants.

First: The "hostname" command.

You can use the hostname command to see the current host name of the system.

# hostname

You can also use the hostname command to change the host name of the machine.

# hostname

Then issue the hostname command again to see the changes.
# hostname

This only makes a temporary or non-persistent change of hostname.

Second: The /etc/sysconfig/network configuration file. (preferred method)

In order for the change to survive a reboot, or to make it persistent, you must change it in the /etc/sysconfig/network-scripts/ifconfig-eth0 file.

Open the file in your favorite editor and change the following line to reflect your desired hostname.

After making changing to the configuration file you need to restart the network service in order to read that file.

/etc/init.d/network restart
NOTE: Do not do this remotely (via ssh) or you will lose your connection.

If you issue the hostname command now, you will see the hostname has changed.

Third: The /proc/sys/kernel/hostname entry.

Another simple way to change the hostname is to echo the hostname into the /proc/sys/kernel/hostname file.

echo "" > /proc/sys/kernel/hostname

NOTE: Using the /etc/sysconfig/network file is the preferred method to set the permanent hostname of a system.  Anything in the /proc/sys/kernel/hostname file will be overridden by the /etc/sysconfig/network file during a reboot.

Thursday, November 27, 2014

Hostname Command Examples in Linux

Hostname is the name of the system or server you are logged into. The hostname can also refer to the sitename or computer name. As an example, if an organization domain name is "" and a specific computer name in that doman is "linux", then the hostname of the computer is "".
The syntax of hostname command in unix or linux system is
hostname [options] [file]

The options of hostname command are:
-a : Prints the alisa name of the host if created any.
-d : prints the domain name
-i : prints the ip address of the host
-s : prints the shortname of the host.
-v : verbose data
-V : version information
-h : help about hostname command

Hostname Command Examples:

1. Print the hostname of the system The basic functionality of the hostname command is to display the name of the system on the terminal. Just type the hostname on the unix terminal and press enter to print the hostname.
> hostname

2. Ip address of the computer You can find the ip address of the computer by using the -i option with hostname command.
> hostname -i

3. Print the domain name To know the domain name where the computer resides, use the -d option with hostname command.
> hostname -d

4. Short hostname By default the hostname command prints the complete name of the computer. You can print a short name by using the -s option. This prints the name upto the first dot in the full hostname.
> hostname -s

5. Getting help To get help about the hostanme command either use the man command or the -h option with hostname command.
> man hostname
> hostname -h