syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
How to change hostname on Centos Linux?

I often work with VirtualBox.

http://en.wikipedia.org/wiki/VirtualBox

If I install VirtualBox on a laptop and then install Linux inside VirtualBox, the laptop is called the Host-OS and Linux is called the Guest-OS or the Guest.

After I install Linux as a Guest, I often want to change the hostname of the Guest.

It is easy, just edit /etc/sysconfig/network and then reboot:
root@cen115.dan / # 
root@cen115.dan / # 
root@cen115.dan / # cd /etc/sysconfig
root@cen115.dan /etc/sysconfig # 
root@cen115.dan /etc/sysconfig # cat network
NETWORKING=yes
HOSTNAME=cen115.dan
NTPSERVERARGS=iburst
root@cen115.dan /etc/sysconfig # 
root@cen115.dan /etc/sysconfig # 
root@cen115.dan /etc/sysconfig # sed -i '2s/cen115/cen114/' network
root@cen115.dan /etc/sysconfig # 
root@cen115.dan /etc/sysconfig # cat network
NETWORKING=yes
HOSTNAME=cen114.dan
NTPSERVERARGS=iburst
root@cen115.dan /etc/sysconfig # 
root@cen115.dan /etc/sysconfig # hostname
cen115.dan
root@cen115.dan /etc/sysconfig # 
root@cen115.dan /etc/sysconfig # shutdown -r now

Broadcast message from dan@cen115.dan
	(/dev/pts/0) at 22:16 ...

The system is going down for reboot NOW!
root@cen115.dan /etc/sysconfig # 
Connection to i114 closed by remote host.
Connection to i114 closed.
dan@feb ~ $ 
dan@feb ~ $ 

I wait a bit.

I reconnect using the same IP-address which should remain unchanged:


dan@feb ~ $ 
dan@feb ~ $ 
dan@feb ~ $ ssh i114
Last login: Sat Jan 31 21:47:09 2015 from i117
dan@cen114.dan ~ $ 
dan@cen114.dan ~ $ 
dan@cen114.dan ~ $ hostname
cen114.dan
dan@cen114.dan ~ $ 
dan@cen114.dan ~ $ 
dan@cen114.dan ~ $ 
Often I also want to change the IP-address.

For that task I usually right click on the network indicator of the Guest desktop and then click 'Edit Connections...'.

Linux then serves me an simple form which I use to change the IP-address.

After I change the IP-address I usually reboot to get the best behavior from the Guest.

syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me