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
通过回显主机名文件获取主机名

使用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 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
获取完全合格的主机名

主机名文件(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
更改主机名

获取域名(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
如何获取Linux的主机名和域名? 信息移植
.u02a196eb89f32270ebe2e8b1811f58ba , .u02a196eb89f32270ebe2e8b1811f58ba .postImageUrl , .u02a196eb89f32270ebe2e8b1811f58ba .centered-text-area { min-height: 80px; position: relative; } .u02a196eb89f32270ebe2e8b1811f58ba , .u02a196eb89f32270ebe2e8b1811f58ba:hover , .u02a196eb89f32270ebe2e8b1811f58ba:visited , .u02a196eb89f32270ebe2e8b1811f58ba:active { border:0!important; } .u02a196eb89f32270ebe2e8b1811f58ba .clearfix:after { content: ""; display: table; clear: both; } .u02a196eb89f32270ebe2e8b1811f58ba { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u02a196eb89f32270ebe2e8b1811f58ba:active , .u02a196eb89f32270ebe2e8b1811f58ba:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u02a196eb89f32270ebe2e8b1811f58ba .centered-text-area { width: 100%; position: relative; } .u02a196eb89f32270ebe2e8b1811f58ba .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u02a196eb89f32270ebe2e8b1811f58ba .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u02a196eb89f32270ebe2e8b1811f58ba .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u02a196eb89f32270ebe2e8b1811f58ba:hover .ctaButton { background-color: #E67E22!important; } .u02a196eb89f32270ebe2e8b1811f58ba .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u02a196eb89f32270ebe2e8b1811f58ba .u02a196eb89f32270ebe2e8b1811f58ba-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u02a196eb89f32270ebe2e8b1811f58ba:after { content: ""; display: block; clear: both; }

LEARN MORE  Linux Dig Command Tutorial With Examples

.u02a196eb89f32270ebe2e8b1811f58ba , .u02a196eb89f32270ebe2e8b1811f58ba .postImageUrl , .u02a196eb89f32270ebe2e8b1811f58ba .centered-text-area { min-height: 80px; position: relative; } .u02a196eb89f32270ebe2e8b1811f58ba , .u02a196eb89f32270ebe2e8b1811f58ba:hover , .u02a196eb89f32270ebe2e8b1811f58ba:visited , .u02a196eb89f32270ebe2e8b1811f58ba:active { border:0!important; } .u02a196eb89f32270ebe2e8b1811f58ba .clearfix:after { content: ""; display: table; clear: both; } .u02a196eb89f32270ebe2e8b1811f58ba { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u02a196eb89f32270ebe2e8b1811f58ba:active , .u02a196eb89f32270ebe2e8b1811f58ba:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u02a196eb89f32270ebe2e8b1811f58ba .centered-text-area { width: 100%; position: relative; } .u02a196eb89f32270ebe2e8b1811f58ba .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u02a196eb89f32270ebe2e8b1811f58ba .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u02a196eb89f32270ebe2e8b1811f58ba .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u02a196eb89f32270ebe2e8b1811f58ba:hover .ctaButton { background-color: #E67E22!important; } .u02a196eb89f32270ebe2e8b1811f58ba .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u02a196eb89f32270ebe2e8b1811f58ba .u02a196eb89f32270ebe2e8b1811f58ba-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u02a196eb89f32270ebe2e8b1811f58ba:after { content: ""; display: block; clear: both; }

了解更多带有示例Linux Dig命令教程

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

如何获取Linux的主机名和域名?相关推荐

  1. Linux修改主机名和域名

    在/etc里有一个hostname这个是主机名存放文件,修改主机名就在这里面修改,用命令: vim /etc/hostname 进入后直接按下键盘上的D键,一下不行就两下,D键就将原有的主机名给删了( ...

  2. Linux修改主机名和域名映射

    启动命令终端,在任何目录下执行命令 cd /etc/sysconfig,切换到该目录并查看目录 下的文件,可以发现存在文件 network 在/etc/sysconfig 目录下找到文件 networ ...

  3. Linux命令之获取和修改主机名hostname

    概述 hostname 命令可以获取当前主机名和临时修改主机名. 语法 该命令的语法如下: hostname [选项] [参数] 该命令支持的选项有: 选项 说明 -a 显示主机别名 -d 显示DNS ...

  4. linux uts namespace 提供了主机名和域名的隔离 docker中被用到

    UTS,UNIX Time-sharing System namespace提供了主机名和域名的隔离.能够使得子进程有独立的主机名和域名(hostname),这一特性在Docker容器技术中被用到,使 ...

  5. 1.Java获取本机IP地址,主机名,域名

    1.如何在程序中获取本机的IP地址,主机名以及域名呢? 在java中,我们可以利用java.net.InetAddress这个类来实现. InetAddress 类提供了操作 IP 地址的各种方法.该 ...

  6. 【linux】主机名被改为bogon原理分析|修改主机名hostname的方法

    目录 linux主机名被更改为bogon原理分析 修改主机名的方法 1.临时修改,重启失效 2.永久生效 linux主机名被更改为bogon原理分析 博客原址:http://blog.csdn.net ...

  7. Linux修改主机名的两种方法

    Linux修改主机名的两种方法 文章目录 先展示一下效果 一.通过hostname命令直接更改主机名(不是永久) 1.显示当前的主机名 2.更改主机名 二.通过修改配置文件(永久改) 1.hostna ...

  8. Linux hostname主机名配置文件与文件 /etc/hosts解说

    Linux hostname经过长时间的发展,这里我发表一下个人理解,下面就这就来讲术Linux hostname.今天又开始写网络文档了,先写一篇小一点的练练手,本来计划了一篇比较大的网络基础文档, ...

  9. Linux 修改主机名的两种方法

    Linux 修改主机名的两种方法 一.使用Linux系统命令修改主机名 通过man获取帮助 hostnamectl 用法 修改 重启生效 二.通过修改配置文件修改主机名 编辑配置文件 修改 重启生效 ...

  10. Linux查看主机名、系统安装版本等信息

    Linux查看主机名.系统安装版本等信息 一.hostnamectl查看主机名 1.1 查看主机名 1.2 临时设置主机名 1.3 手动修改文件 1.4 命令行永久修改 1.5 重启hostname服 ...

最新文章

  1. 如何将视频下载并且转码拼接
  2. HttpWebRequest post提交XMl参数请求,
  3. 在Java中避免空检查
  4. 【Set jsonObj = toJson( jsonString )】创建JSON实例
  5. 前端学习(2702):重读vue电商网站23之element-ui 如何按需导入
  6. Windows7 登陆失败:未知的用户名或密码错误 网络共享文件夹
  7. 使用windows crypto API加密解密
  8. SAP License:SAP-Coding Block
  9. 一篇文章教你学会如何使用CSS中的雪碧图(CSS Sprite)
  10. VMware安装CentOS过程(初学linux)
  11. 器件基础知识——电感
  12. linux root邮箱地址,Linux中自动送给root的mail可以发给互联网上的emai? 爱问知识人...
  13. excel怎么筛选出自己想要的内容
  14. 有余记账(h5记账类项目)
  15. Matlab基于颜色的车牌识别
  16. layUI中使用layer.open,在content打开数据表格,获取值并返回
  17. 面向对象多项式求导总结
  18. windows搭建frp服务器_Windows平台下FRP内网穿透的搭建
  19. 搜索引擎Bing必应高级搜索语法
  20. 第一章 分布式计算概述

热门文章

  1. C++ 野指针和悬空指针
  2. 使用C语言绘制变换前与变换后的三角形图形——变换矩阵
  3. php使用iframe框架,ThinkPHP后台首页使用iframe(框架)
  4. 论文阅读(1)Large Pose 3D Face Reconstruction from a Single Image via Direct Volumetric CNN Regression
  5. JOI2014Final 飞天鼠
  6. windows10流媒体服务器文件查看,win10的流媒体怎样启用?Win10启用流媒体的方法
  7. ​​什么是图形工作站?我们日常接触的计算机类别
  8. CST电磁仿真GPU计算工作站、集群最新配置推荐2022
  9. 国际象棋 java_A和B和国际象棋
  10. IOS把图片做成圆形效果