How to set hostname to your server ?

Started by Dipak Bhoi, January 21, 2014, 11:32:37 PM

Previous topic - Next topic

Dipak Bhoi

Hello guys,

This post cover how to set the server hostname on linux.

Quotelogin as: root 
    root@example.com's password: 
    Last login: Tue Jan 21 06:33:17 2014
    [root@example ~]# hostname 
    example.com
 

You can also check via sysctl kernel.hostname

Quote#sysctl kernel.hostname 
    kernel.hostname = example.com 

I wish to set for this server is instructor.example.com
Quote# hostname instructor.example.com 

This will set the hostname.
Quote# hostname 
    instructor.example.com 
once the server is rebooted, hostname is changing to example.com.

To permanently change the hostname, You need to edit the network file at /etc/sysconfig/network

Quote#vi /etc/sysconfig/network
   
NETWORKING=yes 
HOSTNAME=example.com 
GATEWAYDEV=eth0 
GATEWAY=192.168.0.1

You will have to edit the HOSTNAME entry.

QuoteHOSTNAME=instructor.example.com 

Enjoy !!!

MilesWeb - 30-Day Money Back
cPanel Web Hosting - cPanel Hosting in India
Grab a Free SSL for your website.  WordPress Optimized Solution.