1. Logon as the root user to your Linux Server.
[larry@localmachine ~]$ su –
Password:
Last login: Thu Jun 11 12:29:24 EDT 2017 on pts/1
[root@localmachine ~]#
2. You must edit the file /etc/hostname to change the local machine name. You can generate a statement to update /etc/hostname with the following bash command:
cat /etc/hostname | awk -F. ‘{print “\n\n perl -pi.bak -e ‘”‘”‘s/”$1″/
[root@localmachine ~]# cat /etc/hostname | awk -F. ‘{print “\n\n perl -pi.bak -e ‘”‘”‘s/”$1″/
perl -pi.bak -e ‘s/localmachine/
[root@localmachine ~]#
3. Take the resulting string and replace the text
Original Perl Command output:
perl -pi.bak -e ‘s/localmachine/
Edited Perl Command output: (New Server Name)
perl -pi.bak -e ‘s/localmachine/linux1/g’ /etc/hostname
[root@localmachine ~]# perl -pi.bak -e ‘s/localmachine/linux1/g’ /etc/hostname
[root@localmachine ~]#
4. Reboot your Linux Server.
[root@localmachine ~]# reboot
5. Logon to your Linux Server after reboot completes and see new name of Server with command: hostname.
[larry@linux1 ~]$ su –
Password:
Last login: Thu Jun 11 14:31:50 EDT 2017 from 10.30.15.69 on pts/1
[root@linux1 ~]# hostname
linux1.localdomain
[root@linux1 ~]#
6. This completes changing LINUX Server name.
Larry Catt, OCP