Add

Tuesday, 26 November 2013

HOSTNAME - Secrete Key of Linux

Setting up HOSTNAME in Linux

In any network HOSTNAME represents a system for various purpose from application end to mail, web and DB server etc, anything messed up in HOSTNAME service will get disrupted. Learning to re(set) the HOSTNAME very essential key step of any initial troubleshooting or fixing issue.

You should fallow naming conventions while choosing a HOSTNAME in any production site – something more meaningful geographical locations, famous gods, Highest mountain ranges. I would say it like MyProdApp1.shiva.com, MyDbStage.krishna.com, …. So would be easier for anyone to remember.

Only Constraints are -
·      It cannot be longer than 64 characters
·      It can only contain letters, numbers, and dashes

Check your current hostname by using cmd.

# hostname
ProdApp1

FQDN – Fully Qualified Domain Name nothing but your hostname + domain (something.org or anything.com) combined together. 
         
# hostname –f
ProdApp1.himalayan.com

( hostname = ProdApp1  and domainname = himalayan.com )

Five basic Step to get your hostname working fine.
         
STEP1:  
Setting the Hostname Using hostname command

# hostaname –v ProdApp2
Setting hostname to ProdApp2
         
         
STEP2:
Modifying the old hostname

# vi /etc/hostname                              (Debian / Ubuntu)
ProdApp2

Debian has an init script, /etc/init.d/hostname.sh which is called at boot time and sets the hostname what is given in /etc/hostname.
or
sudo service hostname start              
To change the hostname, place only the unqualified hostname in /etc/hostname and run sudo /etc/init.d/hostname.sh

# vi /etc/HOSTNAME                        (SUSE)
ProdApp2

Or

Edit line HOSTNAME="”

# vi /etc/sysconfig/network               (CentOS /RedHat/ Fedora)
         
NETWORKING=yes
HOSTNAME="ProdApp2 "
GATEWAY="192.168.10.10"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"

STEP 3:
Make new entry /etc/hosts for FQDN resolution.

192.168.10.10                 ProdApp2.himalayan.com                ProdApp2

STEP 4:
Now job would be setting it permanent without any reboot (You won’t get a downtime for just resetting HOSTNAME in Production sites)

#service network restart

Or

#/etc/init.d/network restart

STEP 5:
Checking hostname is set to correct name by using
# hostname –f
ProdApp2.himalayan.com


That’s it – you are done! – Not a big task, but its key task for sure, In STEP 1 command will change the HOSTNAME to new value temporarily.
For Permanent fix, change the configuration file as discussed in STEP 2 & 3 and next time it boots it will read the those configuration file for setting hostname.



No comments:

Post a Comment