Applied on = CentOs, RedHat, Fedora…etc
Here is a simple script that will change Hostname Automatically.
it will just ask you to desired hostname type hostname then hit enter and that’s it…
Download Hostname.sh
or
# wget http://broexperts.com/dl/hostname.sh
Contents of Hostname.sh file
#!/bin/bash #Author: Hafiz Haider #Email: admin@broexperts.com #Date: 28-01-2012 #Purpose: Auto Hostname Changing clear echo "Please Enter your Desired Hostname" read HOSTNAME cat /etc/sysconfig/network | grep NETWORKING > /tmp/hostname.txt echo HOSTNAME=$HOSTNAME >> /tmp/hostname.txt cat /tmp/hostname.txt > /etc/sysconfig/network hostname $HOSTNAME rm -fr /tmp/hostname.txt #END
Step 1:
Run Script
# bash hostname.sh
Step 2:
Shell Script : It will ask you to put Desired Hostname and hit enter:
Pleae Enter Your Desired Hostname cent6.broexperts.com
That’s All…!!
Now relogin and see your hostname has been changed.