Thursday, August 16, 2012

Ubuntu Change host name

SkyHi @ Thursday, August 16, 2012

Ubuntu:
[user1@ws1 ~]$ sudo vi /etc/hosts
127.0.0.1       localhost
127.0.1.1       client1.linux.local client1

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

[user1@ws1 ~]$ sudo vi /etc/hostname
client1

[user1@ws1  ~]$ sudo hostname client1.linuxcbt.local


Pretty much all software is sensitive to correctly setting the hostname. While I was working at Digg I once brought the entire site down for 2 hours due to making a seemingly innocent change in /etc/hoststhat affected the system's notion of hostname. Tread lightly. That said, you may be slightly confused here. I don't think the HOSTNAME= setting is directly equivalent to how Debian-based distributions use/etc/hostname.
What works for me in a heterogeneous environment is:
1. Set the hostname in the vendor-recommended manner, using a conditional in your config management software.
2. Use the "hostname" command to set the hostname used by the kernel, etc.
3. In /etc/hosts:

127.0.0.1    localhost
10.0.0.1     hostname.example.com     hostname



Centos:

A typical RHEL/CentOS server setup for a server named "Rizzo" with internal domain "ifp.com", would look like:
/etc/sysconfig/network:
Rizzo
-
/etc/hosts:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.100.13   Rizzo.ifp.com rizzo
-
[root@Rizzo ~]# hostname 
Rizzo
-
/var/log/messages snippet:
Dec 15 10:10:13 Rizzo proftpd[19675]: 172.16.100.13 (::ffff:206.15.236.182[::ffff:206.15.236.182]) - Preparing to               
 chroot to directory '/app/upload/GREEK'
Dec 15 10:10:51 Rizzo proftpd[20660]: 172.16.100.13 (::ffff:12.28.170.2[::ffff:12.28.170.2]) - FTP session opened.
Dec 15 10:10:51 Rizzo proftpd[20660]: 172.16.100.13 (::ffff:12.28.170.2[::ffff:12.28.170.2]) - Preparing to chroot                
to directory '/app/upload/ftp/SRRID'




REFERENCES
http://serverfault.com/questions/331936/setting-the-hostname-fqdn-or-short-name
http://ubuntublog.org/how-to-change-your-hostname-in-ubuntu.htm