Skip to content

Instantly share code, notes, and snippets.

@rpuglielli
Created October 5, 2018 19:59
Show Gist options
  • Save rpuglielli/b923a1bf3e9b838238becdc5abb982b0 to your computer and use it in GitHub Desktop.
Save rpuglielli/b923a1bf3e9b838238becdc5abb982b0 to your computer and use it in GitHub Desktop.
Change a server's hostname in CentOS
Using a text editor, open the server’s /etc/sysconfig/network file.
$ sudo vi /etc/sysconfig/network
# Modify the HOSTNAME= value to match your FQDN hostname.
HOSTNAME=myserver.domain.com
For internal networking, change the host that is associated with the main IP address for your server (found at /etc/hosts).
127.0.0.1 localhost localhost.localdomain
123.45.67.89 hostname.domain.com hostname
-- INSERT -- 2,43-57 ALL
Run the hostname command. This command lets you change the hostname on the server that the command line remembers, but it does not actively update all programs that are running under the old hostname.
[root@host ~]# hostname hostname.domain.com
[root@host ~]# hostname
Returns:
hostname.domain.com
[root@host ~]#
Restart networking on your server to ensure that changes will persist on restart.
$ /etc/init.d/network restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment