当前位置:网站首页>The return values of hostname -f and uname -n may be different
The return values of hostname -f and uname -n may be different
2022-06-29 08:38:00 【Migrant worker Lao Wang】
Blog home page :https://tomcat.blog.csdn.net
Blogger's nickname : Lao Wang of migrant workers
Main areas :Java、Linux、K8S
We look forward to your attention, praise and collection comments
Catalog
At work , Due to the operation requirements of the software used , I met Linux Most systems will set the host name to something like test.laowang.cn Such a fully qualified domain name . In contact with Linux At the beginning of the , I learned through the Internet , The command to get the fully qualified domain name is hostname -f , And when writing scripts , Use this command frequently . And then , I took over what other colleagues wrote shell Script , Read uname -n This order . This command is the first time I have seen , After checking its general function on the Internet , Then run this command on the computer , The fully qualified domain name is also found . then , I thought hostname -f And uname -n The return value of , It's the same , All are Linux The fully qualified domain name of the system .
The return value is the same
In general , If in /etc/hostname and /etc/hosts The same host name is written in , that hostname -f And uname -n The return value of is the same , As shown in the figure below :

When the return value is different
Only later , The return values of these two commands are likely to be different . If you will /etc/hostname The value in is set to a single word that is not separated by a dot . meanwhile , stay /etc/hosts in , For this machine ip Set two machine names , And only the shorter one is related to /etc/hostname Consistent values for , You can make hostname -f And uname -n The return value of is different . As shown in the figure below :
Compare hostname and uname command
By looking at the help of the two commands , I can see hostname It is mainly used to view or set the host name -f The parameter indicates the fully qualified domain name ,-s Parameter represents short name . and uname The full English name of the command is “Unix name”, Used to display system related information , For example, host name 、 Kernel version number 、 Hardware architecture, etc ,-n Indicates the name of the output local network node .
Current operations show that ,hostname -f And uname -n The return value of may be different ,hostname -s And uname -n The return value of is generally the same . But I can't tell hostname -s And uname -n It's two equivalent commands , So when we program , It's best not to be in a program , Alternate the two commands to get the hostname .


If you want to reprint , Please indicate the source of this article : Migrant worker Lao Wang's CSDN Blog https://blog.csdn.net/monarch91 .
边栏推荐
猜你喜欢

【无标题】

Matlab usage
![[microservices openfeign] timeout of openfeign](/img/b1/9bc92250b4d544c704d2af5c08d059.png)
[microservices openfeign] timeout of openfeign

对比HomeKit、米家,智汀家庭云版有哪些场景化的体验

TypeScript 變量聲明 —— 類型斷言

New spark in intelligent era: wireless irrigation with Lora wireless transmission technology

使用adb命令调试夜神模拟器

How to recover data loss of USB flash disk memory card

批量处理实验接触角数据-MATLAB分析

分布式数字身份的几个“非技术”思考
随机推荐
A review of visual SLAM methods for autonomous driving vehicles
Notes mosaïque
对比HomeKit、米家,智汀家庭云版有哪些场景化的体验
Is it really safe to open a stock account online? Find the answer
x86和x64的区别
蓝图基础
练习-选择排序
[redis] redis6 learning framework ideas and details
开发小技巧-图片资源管理
Some behaviors of Apple developers that are prone to investigation
《乔布斯传》英文原著重点词汇笔记(七)【 chapter five】
Self attention mechanism
Exercise - select sort
VMware vcenter/esxi series vulnerability summary
Some "non-technical" Thoughts on distributed digital identity
Excel中VLOOKUP函数简易使用——精确匹配或近似匹配数据
Target tracking [single target tracking (vot/sot), target detection, pedestrian re identification (re ID)]
Sorting out easily confused words in postgraduate entrance examination English 【 flash 】
【LoRaWAN节点应用】安信可Ra-08/Ra-08H模组入网LoRaWAN网络的应用及功耗情况
壁纸小程序源码双端微信抖音小程序
