Host name is the identifier of a system in the network. Host name can be get with different ways in Linux. Host name is generally put in the /etc/hostname file.

主机名是网络中系统的标识符。 主机名可以在Linux中以不同的方式获得。 主机名通常放在/ etc / hostname文件中。

通过回显主机名文件获取主机名 (Get Host name By Echoing Host name File)

Host name information is stored in a file /etc/hostname . So we can simple print the host name to the terminal with echo command like below.

主机名信息存储在文件/etc/hostname 。 因此,我们可以使用echo命令将主机名简单地打印到终端,如下所示。

$ cat /etc/hostname
Get Host name By Echoing Host name File
Get Host name By Echoing Host name File
通过回显主机名文件获取主机名

使用hostname命令获取主机名(Get Host name With hostname Command)

We can get host name with hostname command. This will only list host name and will not print domain related information.

我们可以使用hostname命令获取主机名。 这只会列出主机名,而不会打印与域相关的信息。

$ hostname
Get Host name With host name Command
Get Host name With host name Command
使用主机名获取主机名命令

获取完全合格的主机名(Get Fully Qualified Host name)

We can get fully qualified host name which provides full name with domain information.

我们可以获得完全合格的主机名,该主机名提供全名和域信息。

$ hostname -f
Get Fully Qualified Host name
Get Fully Qualified Host name
获取完全合格的主机名

主机名文件(Hostname File)

Host name file /etc/hostname will only provide host name with fully qualified domain name. There will any no other data in this file.

主机名文件/ etc / hostname将仅提供具有完全限定域名的主机名。 该文件中将没有其他数据。

更改主机名 (Change Host name)

As the hostname is stored in the /etc/hostname file we can change the hostname by editing this file. We will set the hostname as ubu1 with the following echo command. Keep in mind that in order to change /etc/hostname file we require root privileges which can be get with the sudo command.

由于主机名存储在/etc/hostname文件中,因此我们可以通过编辑该文件来更改主机名。 我们将使用以下echo命令将主机名设置为ubu1 。 请记住,为了更改/etc/hostname文件,我们需要可以使用sudo命令获得的root特权。

$ sudo echo "ubu1" > /etc/hostname
Change Hostname
Change Hostname
更改主机名

获取域名(Get Domain Name)

Domain name information is about the systems network configuration.

域名信息与系统网络配置有关。

$ dnsdomainname 
cen1.test

如何获取Linux的主机名和域名? 信息移植 (How To Get Host Name and Domain Name Of Linux? Infografic)

How To Get Host Name and Domain Name Of Linux? Infografic
How To Get Host Name and Domain Name Of Linux? Infografic
如何获取Linux的主机名和域名? 信息移植
LEARN MORE  Linux Dig Command Tutorial With Examples
了解更多带有示例Linux Dig命令教程

翻译自: https://www.poftut.com/get-host-name-domain-name-of-linux/

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐