Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to set or change Hostname in Linux

In Linux, it is not difficult to change the Hostname. In Linux, you can change hostname using hostname command.

If you execute hostname command without any parameter, it will display current hostname.

If you want to change or set hostname of your Linux system, simply run:

# hostname new-hostname

The above command will change the hostname immediately but the real problem is, original hostname will be restored again on next reboot.

Set System Hostname Permanently in Linux

Newer version of different Linux distributions such as latest Ubuntu, Debian, CentOS, Fedora, RedHat, etc. comes with systemd, a system and service manager that provides a hostnamectl command to manage hostnames in Linux.

To Set System Hostname on SystemD based distributions, we will use hostnamectl command as follow:

# hostnamectl set-hostname new-hostname

For older Linux distributions, which uses SysVinit in short init, can have their hostnames changed by simply editing the hostname file.

# vi /etc/hostname

Now, you need to add another record for the hostname:

# vi /etc/hosts

For example:

127.0.0.1 new-server.webhostingdiscussion.net

Then you need to restart service as follow:

# /etc/init.d/hostname restart

On RHEL/CentOS based systems that use init, the hostname is changed by modifying network file:

# vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=”new-server.webhostingdiscussion.net”
GATEWAY=”192.168.0.1″
GATEWAYDEV=”eth0″
FORWARD_IPV4=”yes”



This post first appeared on Web Hosting Blog - Web Hosting Discussion, please read the originial post: here

Share the post

How to set or change Hostname in Linux

×

Subscribe to Web Hosting Blog - Web Hosting Discussion

Get updates delivered right to your inbox!

Thank you for your subscription

×