Академический Документы
Профессиональный Документы
Культура Документы
This is recommended
method.
2. nmtui command : Control the system hostname using text user interface (TUI).
3. nmcli command : Control the system hostname using CLI part of NetworkManager.
Types of hostnames
The hostname can be configured as follows
$ hostnamectl
## OR ##
$ hostnamectl status
Sample outputs:
Chassis: n/a
Virtualization: oracle
Chassis: n/a
Virtualization: oracle
Architecture: x86_64
How do I delete a particular host name?
Fig.04: CentOS 7 / RHEL View Host Name Details Using hostnamectl Command
Method #3: nmcli command
The nmcli is a command line tool for controlling NetworkManager and reporting
network status.
-------------------------------------------
Static – The static host name is traditional host which can be chosen by the user and
is stored in /etc/hostname file.
Transient – The transient host name is maintained by the kernel and can be
changed by DHCP and mDNS.
Pretty – It is a free form UTF -8 host name for the presentation to the user.
• 64 character in a length
• Recommend to have FQDN
• Consists of a-z,A-Z, 0-9, “-”, “_” and “.” only
How to Change:
Before changing the host name, let’s check the current host name.
1. nmtui tool:
NetworkManager tool is used to set the static host name in /etc/hostname file.
2. hostnamectl:
hostnamectl is used to change the host name, with this tool we can change all the
three class of host name; here we look only static host name.
Check the host name again (Close the session and open new session using putty or
console)
If you use this command, you do not require to notify the change of the host name.
Close the current session and re launch the terminal.
3. nmcli tool:
It can be used to query and setup the static host name in /etc/hostname file.
restart the hostnamed to force the hostnamectl to notice the change of the static
host name.
4. Edit /etc/hostname
This is the simple but requires a reboot of the server to take an effect.
Note: Use the hostnamectl to change the host name, which is fair better than
other commands and does not require to update the kernel about the change
in the host name.
---------------------------
# hostname
# hostname -s
# hostname -f
Check Hostname in CentOS 7
You can also display a Linux system hostname by inspecting the content
of /etc/hostname file using the cat command.
# cat /etc/hostname
# hostnamectl
In order to apply the new hostname, a system reboot is required, issue one
of the below commands in order to reboot a CentOS 7 machine.
# init 6
# systemctl reboot
# shutdown -r
Set CentOS 7 Hostname
# vi /etc/hostname
# sysctl kernel.hostname
# sysctl kernel.hostname=new-hostname
# sysctl -w kernel.hostname=new-hostname
# sysctl kernel.hostname
# hostnamectl
Change CentOS 7 Hostname
hostname types
We can configure 3 hostname types is CentOS/RHEL 7 :
Hostname Type Description
Pretty Assigned by the system admin. Its can be used as Description like “Oracle
Method 1 : hostnamectl
To get the current hostname of the system :
# hostnamectl status
Static hostname: localhost.localdomain
Icon name: computer
Chassis: n/a
Machine ID: 55cc1c57c7f24ed0b0d352648024cea6
Boot ID: a12ec8e04e6b4534841d14dc8425e38c
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
To set new hostname (geeklab) for the machine :
# hostnamectl
Static hostname: geekslab
Pretty hostname: Geeks LAB
Icon name: computer
Chassis: n/a
Machine ID: 55cc1c57c7f24ed0b0d352648024cea6
Boot ID: a12ec8e04e6b4534841d14dc8425e38c
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
Method 2 : nmcli
To view the current hostname :
# hostname
geeklab
Method 3 : nmtui
We can also change the hostname using the nmtui tool :
nmtui
Select the option to “set the hostname” and hit enter
# hostnamectl
Static hostname: geeklab
Icon name: computer
Chassis: n/a
Machine ID: 55cc1c57c7f24ed0b0d352648024cea6
Boot ID: a12ec8e04e6b4534841d14dc8425e38c
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
# cat /etc/hostname
localhost.localdomain
To change the hostname to “geeklab”, replace the content of the /etc/hostname file
with “geeklab”
# echo "geeklab" > /etc/hostname
# cat /etc/hostname
geeklab
Restart the system and verify.
# shutdown -r now
# hostname
geeklab
-------------------
First way
We have been using this way for most of the Linux versions & it works fine
in CentOS/RHEL 7 as well. In this way, we will manually add hostname by
editing /etc/sysconfig/network,
$ vi /etc/sysconfig/network
and add your hostname,
NETWORKING=yes
HOSTNAME=centos7.linux.com
Restart network services to implement the changes.
Second Way
Second way for changing hostname is by using command ‘hostnamectl’.
Hostnamectl is used to change or query hostname. For changing
hostname, run the following command
$ hostnamectl set-hostname “centos7.linux.com”
To view the changes hostname, only run ‘hostnameclt‘ command,
$ hostnamectl
If you completely want to remove the hostname, use ‘hostnamectl set-
hostname “” ‘. This remove the hostname completely.
Third way
Next command to change hostname is ‘nmtui‘. NMTUI or “Network
Manager Text User Interface” utility can used while using CLI or GUI. With
‘nmtui’, we can edit network interfaces & change hostname also.
Type ‘nmtui’ into your shell & a new interface with some options will launch
$ nmtui
next, select ‘set system hostname’ & click ‘ok and enter your desired hostname
, press ‘ok‘ & its done.
Fourth Way
Next method of changing hostname is by using ‘nmcli’ command. It is
meant to be used with nmcli, to view the hostname run the following
command,
$ nmcli general hostname
To change the hostname using nmcli, use the command below,
Fifth way
Last way for changing the hostname is not a preferred way but none the
less it gets the job done. To view the current hostname ,
$ sysctl kernel.hostname
& if you want to change the hostname, run
$ sysctl kernel.hostname=centos7.linux.com
Changes to the hostname will be immediate & you can verify the new
hostname by running any of the above commands to check hostname.
That’ it guys, these were the five ways to change hostname. If you have any
other method that you think i missed, please do share them via the
comment box down below.
-------------------
You have probably needed to change the hostname of your CentOS 7 install for
one reason or the other. Changing the hostname in CentOS 7 is now much simpler
than ever.
If you are ready open up your terminal and follow through this tutorial, and in less
than 10 minutes you will have changed your hostname!
Check Hostname
To check the hostname open your terminal and type the following command:
$ hostname
By default the hostname is localhost.localdomain. To change this you can follow
the following steps
$ sudo vi /etc/hostname
Save changes and then confirm your hostname by using hostname command. If
it has not changed then you need to restart the CentOS 7 server.
Using Hostnamectl
Hostnamectl is a tool that is used control the Linux system hostname. You can
also use this tool to change the hostname in a few easy steps.
$ hostnamectl status
Using Nmtui
To change the hostname you can also use the NetworkManager text interface tool
(nmtui). This is also another very easy method and fairly straight forward.
Using Nmcli
Nmcli is a command line tool for controlling the NetworkManager and can also be
used to change the hostname.
----------------------
Check Hostname
The default hostname of the system is localhost.localdomain. We can change it by editing the file,
/etc/hostname. This can be done by opening the file with a text editor and entering in the desired
hostname.
$ vi /etc/hostname
Please note that after the modification the file must be saved. If it has not changed, then try
restarting the server. Then confirm your new hostname in the hostname file.
Using Hostnamectl
With the help of hostnamectl we can easily control the Linux system hostname. You can also use
this tool to change the hostname in a few easy steps. The present hostname can be checked by:
$ hostnamectl status
Using Nmtui
Network Manager text interface tool (NMTUI) is a graphical interface tool which allows to change
the hostname easily. Type the following command in terminal:
$ nmtui
A list of available options will be shown and you can select the required option from there.
Change the hostname from localhost.localdomain to the desired name. Press OK to apply the
modification done. For further verification type hostname in the command line.
Using Nmcli
This command line tool is used to manage the Network Manager and change the
hostname. The following command can be used to check the hostname:
$ nmcli general hostname
The below given command can be used to change the hostname
$ nmcli general hostname TEST
This will request for your password via a GUI interface. If you are running this command remotely
remember to use root or sudo:
$ sudo nmcli general hostname grace
You can then check the hostname with the command hostname or nmcli general hostname.
If you need any further assistance please contact our support department.
-----------------
https://www.server-world.info/en/note?os=CentOS_7&p=hostname
The
example
for
setting
Hostnam
e of your
system.
[root@localhost ~]#
hostname
localhost.localdomain
# change hostname
[root@localhost ~]#
hostname dlp.srv.world
[root@localhost ~]#
hostname
dlp.srv.world
# just changed
[root@localhost ~]#
hostnamectl set-hostname dlp.srv.world
# show status
[root@localhost ~]#
hostnamectl