RHEL / Centos 7 Change and Set Hostname Command
On a CentOS Linux 7 server you can use any one of the following tool to manage hostnames:- hostnamectl command : Control the system hostname. This is recommended method.
- nmtui command : Control the system hostname using text user interface (TUI).
- nmcli command : Control the system hostname using CLI part of NetworkManager.
Method #1: hostnamectl command
Let us see how to use the hostnamectl command.
$ hostnamectl
## OR ##
$ hostnamectl status
Sample outputs:
Static hostname: centos-7-vm
Icon name: computer
Chassis: n/a
Machine ID: 663f697442a7d2c736c892230000002f
Boot ID: c1ab056f60170cc0c9b63e1d1ea9c8fb
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 host name?
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 verify new settings, enter:
# hostnamectl status
How do I delete a particular host name?The syntax is:
# hostnamectl set-hostname ""
# hostnamectl set-hostname "" --static
# hostnamectl set-hostname "" --pretty
Method #2: nmtui command
You can set host name using nmtui command which has text user interface for new users:
# nmtui
Use the Down arrow key > select the "Set system hostname" menu option > Press the "Ok" buttonFinally, restart hostnamed service by typing the following command
# systemctl restart systemd-hostnamed
To verify new hostname, enter:
# hostnamectl status
Method #3: nmcli command
To view the host name using nmcli command:The syntax is:
# nmcli general hostname
To set the host name using nmcli command:The syntax is:
# nmcli general hostname 10tut
# nmcli general hostname 10tut.localdomain
Finally, restart the systemd-hostnamed service:
# systemctl restart systemd-hostnamed
check cat /etc/sysconfig/network /etc/hostname
Không có nhận xét nào:
Đăng nhận xét