Monday, January 13, 2014

Configure the hostname in CentOS

Test a hostname if working:
nfslookup HOSTNAME
or
nfslookup IP_ADDRESS

to see if there is an entry in the DNS server

First, you need to have a correct network script in /etc/sysconfig/network-script/ifcfg-eth4

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 


DEVICE=eth4                                   //device name
HWADDR=00:26:B9:38:4C:23            // mac address 
TYPE=Ethernet                         
ONBOOT=yes                                  // automatically connected after bootup
NM_CONTROLLED=no                     // does not use Network Manager, use ifcfg-eth4 script
BOOTPROTO=dhcp                         // use DHCP
DHCP_HOSTNAME=sr2s18              // configure DHCP hostname

PEERDNS=yes                                //Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default


Then, configure the hostname:

http://www.rackspace.com/knowledge_center/article/centos-hostname-change

1. set /etc/sysconfig/network

[root@sr2s16 ~]# cat /etc/sysconfig/network
NETWORKING_IPV6=no
HOSTNAME=sr2s16.example.com

NETWORKING=yes

2. configre /etc/hosts

[root@sr2s16 ~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
129.174.114.142 sr2s16.example.com sr2s16
::1 sr2s16.example.com sr2s16

192.168.0.36 sr2s16.example.com sr2s16


3. restart network

$ service network restart









No comments: