Changing your Hostname in CentOS 7
Change Your Hostname In CentOS 7 Using The Hostnamectl Command
On a CentOS 7 Linux server you can use any one of the following tools to manage hostnames:
- hostnamectl command: Control the system hostname. This is the recommended method.
- nmtui command: Control the system hostname using text user interface (TUI).
- nmcli command: Control the system hostname using CLI part of NetworkManager.
The hostname can be configured as follows
- Static hostname assigned by the sysadmin. For example, “server1”, “node10”, or “server42.gozenhost.com”.
- Transient/dynamic hostname assigned by DHCP or mDNS server at runtime.
- Pretty hostname assigned by sysadmin/end-users and it is a free-form UTF8 hostname for presentation to the user. For example, “Manager’s netbook”.
Let’s see step by step hostnamectl command usage.
hostnamectl or hostnamectl status
The above command will have the following result.
Static hostname: centos-7-rc Icon name: computer Chassis: n/a Machine ID: b5470b10ccfd49ed8e4a3b0e953a53c3 Boot ID: f79de79e2dac4670bddfe528e826b61f Virtualization: oracle Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-229.1.2.el7.x86_64 Architecture: x86_64
How do I set the hostname?
The syntax is:
# hostnamectl set-hostname Your-New-Host-Name-Here # hostnamectl set-hostname "Your New Host Name Here" --pretty # hostnamectl set-hostname Your-New-Host-Name-Here --static # hostnamectl set-hostname Your-New-Host-Name-Here --transient
To set hostname to “srv1”, enter:
# hostnamectl set-hostname srv1
To set static hostname to “srv1.gozenhosting.net”, enter:
# hostnamectl set-hostname srv1.gozenhosting.net --static
To set pretty hostname to “srv1 clients main ns server”, enter:
# hostnamectl set-hostname "Senator Padme Amidala's Laptop" --pretty
To verify new settings, enter:
# hostnamectl status
Leave a Reply