当前位置:网站首页>hostname -f与uname -n的返回值可能不同
hostname -f与uname -n的返回值可能不同
2022-06-29 07:52:00 【农民工老王】
博客主页:https://tomcat.blog.csdn.net
博主昵称:农民工老王
主要领域:Java、Linux、K8S
期待大家的关注点赞收藏留言
在工作中,由于使用的软件的运行要求,我遇到的Linux系统大部分会将主机名设置为一个像test.laowang.cn这样的全限定域名。在接触Linux之初,我就通过网络了解到,获取全限定域名的命令是hostname -f ,并在写脚本时,频繁使用这一命令。随后,我接手了其他同事写的shell脚本,读到uname -n 这一命令。这个命令是我第一次看到,在网上查看了其大概作用后,再将这个命令在电脑上运行了一下,发现得到的也是全限定域名。然后,我就以为hostname -f与uname -n的返回值,是一样的,都是Linux系统的全限定域名。
返回值一样的情况
一般情况下,如果在/etc/hostname和/etc/hosts中写入了一样的主机名,那么hostname -f与uname -n的返回值是相同的,如下图所示:

返回值不同的情况
后来才发现,这两个命令的返回值很有可能不一样。如果将/etc/hostname中的值设为不被点号分割的单个单词。同时,在/etc/hosts中,为本机ip设置两个机器名,且只有较短的那个与/etc/hostname的值保持一致,就可以让hostname -f与uname -n的返回值不同。如下图所示:
比较hostname和uname命令
通过查看两个命令的帮助,我可以看出hostname主要是查看或设置主机名 -f 参数表示全限定域名,-s 参数表示短名。而uname命令的英文全称为“Unix name”,用于显示系统相关信息,比如主机名、内核版本号、硬件架构等,-n 表示输出本机网络节点的名字。
目前的各种操作表明,hostname -f与uname -n的返回值可能不同,hostname -s与uname -n的返回值一般相同。但我也不能断定hostname -s与uname -n是两个等价的命令,所以我们在编程时,最好不要在一个程序中,交替使用两个命令来获取主机名。


如需转载,请注明本文的出处:农民工老王的CSDN博客https://blog.csdn.net/monarch91 。
边栏推荐
- Sorting out easily confused words in postgraduate entrance examination English 【 flash 】
- [hcie TAC] question 5-2
- 网上开股票账户真的安全吗?求答案
- hugetlbfs的写时复制
- 城通网盘仿蓝奏网盘源码 附带视频教程
- 智能硬件evt dvt pvt mp
- sql语句concat搜索不出结果
- MySQL按天/周/月/季度/半年/年统计数据
- Soliciting articles and contributions - building a blog environment with a lightweight application server
- [eye of depth wuenda machine learning homework class phase IV] regularization regularization summary
猜你喜欢
A method to quickly connect notebook computers to mobile phone hotspots

Interprocess communication (IPC)
![Speech synthesis: overview [generation task of unequal length sequence relation modeling]](/img/13/bd9def50f0efde49b622d139f63a83.png)
Speech synthesis: overview [generation task of unequal length sequence relation modeling]

U盘内存卡数据丢失怎么恢复,这样操作也可以

ThreadLocal thread variable
![[redis] redis6 learning framework ideas and details](/img/64/836b1f8843a8eb91ff8da8c05ccd87.png)
[redis] redis6 learning framework ideas and details

Résumé des différentes séries (harmoniques, géométriques)

标准|中国支付清算协会发布首个隐私计算金融规范

Talking about Nacos configuration center from Nacos client

SizeBalanceTree
随机推荐
Open an account to buy funds. Is it safe to open an account through online funds-
开户买基金,通过网上基金开户安全吗?-
Voice processing tool: Sox
[eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables
Flutter shared_preferences使用
[hcie TAC] question 5-2
Simple use of AWS elastic Beanstalk
802.11--802.11n协议 PHY
Flutter 文件读写-path_provider
A review of visual SLAM methods for autonomous driving vehicles
Hook 簡介
324. 摆动排序 II / 剑指 Offer II 102. 加减的目标值
[eye of depth wuenda machine learning homework class phase IV] summary of logistic regression
[domain penetration authorization] cve-2020-1472 Netlogon privilege escalation vulnerability
Binary search tree
表格背单词的方法
Explain the garbage collection mechanism (GC) in JVM
Use GPU training in the cloud on the laboratory (take yolov5 as an example)
蓝图基础
ThreadLocal thread variable
