如何获取Linux的主机名和域名?

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/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值