霍嘉豪 發表於 2019-11-6 09:58:00

Centos 7修改hostname浅析

<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><font color="#000000"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt">之前写过一篇博客</font></font></span><font style="font-size: 10.5pt"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn; mso-ascii-font-family: 宋体; mso-fareast-font-family: 宋体"><font face="等线">“<font face="宋体">深入理解Linux修改hostname</font></font></span><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn; mso-ascii-font-family: 宋体; mso-fareast-font-family: 宋体"><font face="宋体">”</font></span></font><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" face="宋体">,里面总结了RHEL 5.7下面如何修改hostname,当然这篇博客的内容其实也适用于CentOS 6,但是自CentOS 7开始,已经跟CentOS 6已经有很大不同了,一直没有总结CentOS 7下修改hostname的相关知识点,今天恰好遇到了这个问题,处理完后遂总结一下。</font></span></font></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">CentOS 7中的启动跟CentOS 6有所区别,CentOS 6启动过程中,会执行/etc/rc.d/rc.sysinit init执行的第一个脚本 这个脚本主要是初始化工作,如设置系统字体,启动swapping,设置主机名等等。CentOS7和CentOS6启动流程差不多,只不过到init程序时候,改为了systemd启动了(并行启动),也就是说CentOS 7不会去执行/etc/rc.d/rc.sysinit这个文件(当然也没有这个文件了)读取hostname的配置,CentOS 7新增了配置文件/etc/hostname,系统启动的时候会读取/etc/hostname这个配置文件来初始化内核主机名。 </font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">另外,我们可以通过配置/etc/hostname修改hostname。也可以通过新增的hostnamectl命令修改。在CentOS 7中,主机名可以分为下面三种类型:</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 36pt; line-height: normal; text-indent: -18pt; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" align="left"><font color="#000000"><span style="line-height: normal; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-ansi-language: zh-cn; mso-fareast-font-family: symbol"><span style="line-height: normal; mso-list: ignore"><font face="Symbol"><font style="font-size: 12pt">·</font></font><span style="line-height: normal"><font face="Times New Roman"><font style="font-size: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font></span></span></span><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt">静态主机名(static):静态主机名也称为内核主机名,是系统在启动时初始化内核的主机名,默认从/etc/hostname读取配置自动初始化静态主机名</font></font></span></font></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 36pt; line-height: normal; text-indent: -18pt; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" align="left"><font color="#000000"><span style="line-height: normal; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-ansi-language: zh-cn; mso-fareast-font-family: symbol"><span style="line-height: normal; mso-list: ignore"><font face="Symbol"><font style="font-size: 12pt">·</font></font><span style="line-height: normal"><font face="Times New Roman"><font style="font-size: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font></span></span></span><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt">瞬态主机名(transient):瞬时主机名是在系统运行时临时分配的主机名,例如,由DHCP等一些系统临时分配的主机名,如果系统存在静态主机名且有效,则不会用到瞬态主机名。</font></font></span></font></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 36pt; line-height: normal; text-indent: -18pt; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" align="left"><font color="#000000"><span style="line-height: normal; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-ansi-language: zh-cn; mso-fareast-font-family: symbol"><span style="line-height: normal; mso-list: ignore"><font face="Symbol"><font style="font-size: 12pt">·</font></font><span style="line-height: normal"><font face="Times New Roman"><font style="font-size: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font></span></span></span><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt">灵活主机名(pretty):静态和瞬态主机名都是要符合域名的字符串,而pretty主机名则可以包含其他一些特殊字符。</font></font></span></font></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">There are three 3 types of hostnames.</font></font></span></p> <ol style="margin-bottom: 0; word-break: normal; padding-left: 0; margin-top: 0; line-height: normal" type="1"> <li class="MsoNormal" style="text-align: left; margin: 0; line-height: normal; mso-layout-grid-align: none; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt"><font face="Courier New"><font color="#000000"><b><span lang="X-NONE" style="mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font style="font-size: 12pt">The static</font></span></b><span lang="X-NONE" style="mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font style="font-size: 12pt">&nbsp;<b>hostname</b> is the most important one, and it’s stored in the <b>/etc/hostname</b> file. This hostname is used among machines to identify a particular server.</font></span></font></font></li></ol> <ol style="margin-bottom: 0; word-break: normal; padding-left: 0; margin-top: 0; line-height: normal" type="1" start="2"> <li class="MsoNormal" style="text-align: left; margin: 0; line-height: normal; mso-layout-grid-align: none; mso-list: l1 level1 lfo3; tab-stops: list 36.0pt"><font face="Courier New"><font color="#000000"><b><span lang="X-NONE" style="mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font style="font-size: 12pt">The pretty hostname</font></span></b><span lang="X-NONE" style="mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font style="font-size: 12pt"> got its name because it allows for more characters and punctuation. It’s more user-friendly, but since it uses non-standard characters, it is not permitted for machine code. The pretty hostname is stored in the <b>/etc/machine-info </b>directory.</font></span></font></font></li></ol> <ol style="margin-bottom: 0; word-break: normal; padding-left: 0; margin-top: 0; line-height: normal" type="1" start="3"> <li class="MsoNormal" style="text-align: left; margin: 0; line-height: normal; mso-layout-grid-align: none; mso-list: l1 level1 lfo4; tab-stops: list 36.0pt"><font face="Courier New"><b><span lang="X-NONE" style="mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font color="#000000"><font style="font-size: 12pt">The transient</font></font></span></b><span lang="X-NONE" style="mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font style="font-size: 12pt"><font color="#000000">&nbsp;<b>hostname</b> is one maintained in the </font><u><span style=""><font color="#0000ff">Linux kernel</font></span></u><font color="#000000">. It is dynamic, meaning it will be lost after a reboot. This approach might be useful if you have a minor job requiring a temporary hostname, but you don’t want to risk making a permanent change that might be confusing.</font></font></span></font></li></ol> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 18pt; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">The static (configured) host name is the one configured in /etc/hostname or a similar file. It is chosen by the local user. It is not always in sync with the current host name as returned by the gethostname() system call. If no host name is configured this property will be the empty string. Setting this property to the empty string will remove /etc/hostname. This hostname should be an internet-style hostname, 7bit ASCII, no special chars/spaces, lower case.</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 18pt; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 18pt; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">The transient (dynamic) host name is the one configured via the kernel's sethostbyname(). It can be different from the static hostname in case DHCP or mDNS have been configured to change the name based on network information. This property is never empty. If no host name is set this will default to "localhost". Setting this property to the empty string will reset the dynamic hostname to the static host name. If no static host name is configured the dynamic host name will be reset to "localhost". This hostname should be an internet-style hostname, 7bit ASCII, no special chars/spaces, lower case.</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 18pt; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0 0 0 18pt; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">The pretty host name is a free-form UTF8 host name for presentation to the user. UIs should ensure that the pretty hostname and the static hostname stay in sync. I.e. when the former is "Lennart's Computer" the latter should be "lennarts-computer". If no pretty host name is set this setting will be the empty string. Applications should then find a suitable fallback, such as the dynamic hostname.</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">如上英文介绍,静态主机名保存在/etc/hostname中,灵活主机名保存在/etc/machine-info,而瞬态主机名一般由内核参数维护,重启后会丢失。</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font color="#000000" size="5">查看主机名(hostname)</font></font></span></b></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">我们可以有很多方式查看主机名,但是我们只能使用命令hostnamectl查看静态、瞬态或灵活主机名,分别使用--static,--transient或--pretty参数。</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: normal; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p> <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 11pt; border: 1px solid rgba(192, 192, 192, 1); font-family: &quot;Courier New&quot;, courier, monospace; width: 97.5%; padding: 4px; direction: ltr; text-align: left; margin: 20px 0 10px; line-height: 11pt; max-height: 1200px; background-color: rgba(244, 244, 244, 1)"> <div id="codeSnippet" style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># cat /etc/hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostnamectl status</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp; Static hostname: localhost.localdomain</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">Transient hostname: MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Icon name: computer-desktop</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Chassis: desktop</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Machine ID: 955dde0d8f7341ebb19a1e247577c410</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Boot ID: 4f2df049135e41c795a655cdf36c1c40</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp; Operating System: CentOS Linux 7 (Core)</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CPE OS Name: cpe:/o:centos:centos:7</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kernel: Linux 3.10.0-862.el7.x86_64</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Architecture: x86-64</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostnamectl </span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp; Static hostname: MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp; Pretty hostname: kerry<span style="color: rgba(0, 96, 128, 1)">'s db</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Icon name: computer-desktop</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Chassis: desktop</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Machine ID: 955dde0d8f7341ebb19a1e247577c410</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Boot ID: 459eb877eeb34d7e910f4eec8ef4a42f</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp; Operating System: CentOS Linux 7 (Core)</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CPE OS Name: cpe:/o:centos:centos:7</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kernel: Linux 3.10.0-862.el7.x86_64</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Architecture: x86-64</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"># hostnamectl --static&nbsp;&nbsp;&nbsp; #查看静态主机名</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"># hostnamectl --transient #查看瞬时主机名</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"># hostnamectl --pretty&nbsp;&nbsp;&nbsp; #查看灵活主机名</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">kerry's db</pre></div></div>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font color="#000000" size="5">设置静态主机名</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font color="#000000" size="5" face="宋体"></font></span></b>&nbsp;</p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000"># hostnamectl set-hostname kerrydb</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font color="#000000"><span style="line-height: 16pt; mso-spacerun: yes"><font style="font-size: 10.5pt">&nbsp; </font></span><font style="font-size: 10.5pt">或</font></font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000"># hostnamectl set-hostname --static kerrydb</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">设置静态主机名立对新连接的会话立即生效,但是对于当前连接则不生效(例如,SecureCRT新开一个窗口就能看到修改结果)。如下测试所,修改静态主机名会立即修改内核中的kernel.hostname</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 11pt; border: 1px solid rgba(192, 192, 192, 1); font-family: &quot;Courier New&quot;, courier, monospace; width: 97.5%; padding: 4px; direction: ltr; text-align: left; margin: 20px 0 10px; line-height: 11pt; max-height: 1200px; background-color: rgba(244, 244, 244, 1)">
<div id="codeSnippet" style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostnamectl set-hostname MyDB</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)"># </span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># cat /proc/sys/kernel/hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">mydb</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostnamectl set-hostname kerrydb</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)"># cat /proc/sys/kernel/hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">kerrydb</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostnamectl set-hostname --static yourdb</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># cat /proc/sys/kernel/hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">yourdb</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"># </pre></div></div>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体">&nbsp;</span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><img title="clip_image001" style="border: 0; background-image: none; padding-top: 0; padding-left: 0; margin: 0; display: inline; padding-right: 0" border="0" alt="clip_image001" src="https://img2018.cnblogs.com/blog/73542/201911/73542-20191106095816537-1678932432.png" width="650" height="227"></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">另外,hostnamectl命令是永久修改hostname,这个命令修改静态主机名,不关会设置内核参数kernel.hostname,它还会立即修改配置文件/etc/hostname,有兴趣可以自己测试一下。</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000"># more /etc/hostname</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">yourdb</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font color="#000000" size="4">设置瞬态主机名</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font color="#000000"><span style="line-height: normal; mso-spacerun: yes"><font style="font-size: 12pt">&nbsp;&nbsp; </font></span><font style="font-size: 12pt"># hostnamectl set-hostname --transient "KerryDB"</font></font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">注意:如果系统存在静态主机名且有效,则不会用到瞬态主机名。</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font color="#000000" size="4">设置灵活主机名</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000"># hostnamectl set-hostname --pretty "kerry's db"</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font color="#000000"><span style="line-height: 16pt; mso-spacerun: yes"><font style="font-size: 10.5pt">&nbsp; </font></span><font style="font-size: 10.5pt">没有设置灵活主机名前,此文件可能不存在(如下所示)</font></font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000"># cat /etc/machine-info</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">cat: /etc/machine-info: No such file or directory</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font color="#000000"><span style="line-height: 16pt; mso-spacerun: yes"><font style="font-size: 10.5pt">&nbsp; </font></span><font style="font-size: 10.5pt">设置后,就能查看此文件(如下所示)</font></font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">#<span style="line-height: normal; mso-spacerun: yes">&nbsp; </span>cat /etc/machine-info</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">PRETTY_HOSTNAME="kerry's db"</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: normal; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 18pt" color="#000000">一些问题测试</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 30pt; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Courier New"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">问题:如果同时设置了/etc/hosts和/etc/hostname,那么服务器重启时,它会读取哪个文件? 我们设置一下这两个后(如下所示),然后重启服务器</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 11pt; border: 1px solid rgba(192, 192, 192, 1); font-family: &quot;Courier New&quot;, courier, monospace; width: 97.5%; padding: 4px; direction: ltr; text-align: left; margin: 20px 0 10px; line-height: 11pt; max-height: 1200px; background-color: rgba(244, 244, 244, 1)">
<div id="codeSnippet" style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># more /etc/hosts</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">127.0.0.1&nbsp;&nbsp; localhost localhost.localdomain localhost4 localhost4.localdomain4</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">::1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; localhost localhost.localdomain localhost6 localhost6.localdomain6</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">10.20.57.24&nbsp; MyDB&nbsp; MyDB.localdomain</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># more /etc/hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">YourDB</pre></div></div>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">重启过后,你会发现静态主机名为YourDB,也就是说重启时读取/etc/hostname这个配置文件来初始化内核主机名,那么我们将/etc/hostname中的静态主机名置空,然后重启服务器。</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 11pt; border: 1px solid rgba(192, 192, 192, 1); font-family: &quot;Courier New&quot;, courier, monospace; width: 97.5%; padding: 4px; direction: ltr; text-align: left; margin: 20px 0 10px; line-height: 11pt; max-height: 1200px; background-color: rgba(244, 244, 244, 1)">
<div id="codeSnippet" style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># cat /dev/null &gt; /etc/hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)"># more /etc/hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"># reboot</pre></div></div>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">测试验证发现,静态主机名变为了n/a,但是显示的主机名为MyDB,那么是否读取了/etc/hosts中的配置呢?我们查看日志,发现下面一些信息。</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 11pt; border: 1px solid rgba(192, 192, 192, 1); font-family: &quot;Courier New&quot;, courier, monospace; width: 97.5%; padding: 4px; direction: ltr; text-align: left; margin: 20px 0 10px; line-height: 11pt; max-height: 1200px; background-color: rgba(244, 244, 244, 1)">
<div id="codeSnippet" style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostname</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)"># hostnamectl</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp; Static hostname: n/a</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp; Pretty hostname: kerry's db</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">Transient hostname: MyDB</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Icon name: computer-desktop</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Chassis: desktop</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Machine ID: 955dde0d8f7341ebb19a1e247577c410</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Boot ID: dfdaa6d51f3942b18d2de98dea2b8906</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp; Operating System: CentOS Linux 7 (Core)</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CPE OS Name: cpe:/o:centos:centos:7</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kernel: Linux </pre></div></div>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 22.5pt; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">我们发现系统启动的时候,在NetworkManager中重新设置hostname的值。具体如下所示:</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">#<span style="line-height: 16pt; mso-spacerun: yes">&nbsp; </span>journalctl -xb | grep hostname</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="Courier New"><font color="#000000"><font style="font-size: 10.5pt">Nov 04 16:03:03 localhost.localdomain systemd: </font></font><span style="line-height: 16pt"><font style="font-size: 10.5pt" color="#ff00ff">Set hostname to &lt;localhost.localdomain&gt;.</font></span></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:15 localhost.localdomain dbus: Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service'</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">-- Subject: Unit systemd-hostnamed.service has begun start-up</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">-- Unit systemd-hostnamed.service has begun starting up.</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:15 localhost.localdomain dbus: Successfully activated service 'org.freedesktop.hostname1'</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">-- Subject: Unit systemd-hostnamed.service has finished start-up</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">-- Unit systemd-hostnamed.service has finished starting up.</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:15 localhost.localdomain NetworkManager: &lt;info&gt;<span style="line-height: 16pt; mso-spacerun: yes">&nbsp; </span> hostname: hostname: using hostnamed</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:15 localhost.localdomain nm-dispatcher: req:1 'hostname': new request (2 scripts)</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:15 localhost.localdomain nm-dispatcher: req:1 'hostname': start running ordered scripts...</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="Courier New"><font color="#000000"><font style="font-size: 10.5pt">Nov 04 16:03:20 localhost.localdomain NetworkManager: </font></font><span style="line-height: 16pt"><font style="font-size: 10.5pt" color="#ff00ff">&lt;info&gt;<span style="line-height: 16pt; mso-spacerun: yes">&nbsp; </span> policy: set-hostname: set hostname to 'MyDB' (from address lookup)</font></span></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:20 MyDB systemd-hostnamed: Changed host name to 'MyDB'</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:20 MyDB nm-dispatcher: req:4 'hostname': new request (2 scripts)</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font style="font-size: 10.5pt" color="#000000" face="Courier New">Nov 04 16:03:20 MyDB nm-dispatcher: req:4 'hostname': start running ordered scripts...</font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><img title="clip_image002" style="border: 0; background-image: none; padding-top: 0; padding-left: 0; display: inline; padding-right: 0" border="0" alt="clip_image002" src="https://img2018.cnblogs.com/blog/73542/201911/73542-20191106095817768-1945038412.png" width="800" height="183"></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><font color="#000000"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt">然后我们从NetworkManager/src/nm-policy.c找到如下代码,简单撸了一下代码,虽然还没有找到直接读取/etc/hosts中hostname的直接证据(C语言已经遗忘的七七八八了,也不想花太多时间深入!),但是实验测试,当/etc/hostname为空时,确实会读取/etc/hosts下面的主机名信息。另外,有点可以确认的是,当/etc/hostname为空时,代码里面首先会将hostname设置为</font></font></span><font style="font-size: 10.5pt"><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn; mso-ascii-font-family: 宋体; mso-fareast-font-family: 宋体"><font face="等线">“</font></span><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体">localhost.localdomain</font></span><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn; mso-ascii-font-family: 宋体; mso-fareast-font-family: 宋体"><font face="等线">”</font></span></font><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt">, 然后,调用_set_hostnam重新设置。</font></font></span></font></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 11pt; border: 1px solid rgba(192, 192, 192, 1); font-family: &quot;Courier New&quot;, courier, monospace; width: 97.5%; padding: 4px; direction: ltr; text-align: left; margin: 20px 0 10px; line-height: 11pt; max-height: 1200px; background-color: rgba(244, 244, 244, 1)">
<div id="codeSnippet" style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">#define FALLBACK_HOSTNAME4 <span style="color: rgba(0, 96, 128, 1)">"localhost.localdomain"</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 0, 255, 1)">static</span>&nbsp;<span style="color: rgba(0, 0, 255, 1)">void</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">_set_hostname (NMPolicy *self,</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">const</span>&nbsp;<span style="color: rgba(0, 0, 255, 1)">char</span> *new_hostname,</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">const</span>&nbsp;<span style="color: rgba(0, 0, 255, 1)">char</span> *msg)</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">{</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; gs_free <span style="color: rgba(0, 0, 255, 1)">char</span> *old_hostname = NULL;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">const</span>&nbsp;<span style="color: rgba(0, 0, 255, 1)">char</span> *name;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* The incoming hostname *can* be NULL, which will get translated to</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; * 'localhost.localdomain' or such in the hostname policy code, but we</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; * keep cur_hostname = NULL in the case because we need to know that</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; * there was no valid hostname to start with.</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* Clear lookup addresses if we have a hostname, so that we don't</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; * restart the reverse lookup thread later.</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">if</span> (new_hostname)</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_clear_object (&amp;priv-&gt;lookup.addr);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* Update the DNS only if the hostname is actually</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; * going to change.</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">if</span> (!nm_streq0 (priv-&gt;cur_hostname, new_hostname)) {</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_free (priv-&gt;cur_hostname);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priv-&gt;cur_hostname = g_strdup (new_hostname);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* Notify the DNS manager of the hostname change so that the domain part, if</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * present, can be added to the search list.</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nm_dns_manager_set_hostname (priv-&gt;dns_manager, priv-&gt;cur_hostname,</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; all_devices_not_active (self));</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; }</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* Finally, set kernel hostname */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">if</span> (!new_hostname)</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = FALLBACK_HOSTNAME4;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">else</span>&nbsp;<span style="color: rgba(0, 0, 255, 1)">if</span> (!new_hostname) {</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_warn_if_reached ();</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = FALLBACK_HOSTNAME4;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; } <span style="color: rgba(0, 0, 255, 1)">else</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = new_hostname;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* Don't set the hostname if it isn't actually changing */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">if</span> (&nbsp;&nbsp; (old_hostname = _get_hostname (self))</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp; (nm_streq (name, old_hostname))) {</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _LOGT (LOGD_DNS, <span style="color: rgba(0, 96, 128, 1)">"set-hostname: hostname already set to '%s' (%s)"</span>, name, msg);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 0, 255, 1)">return</span>;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; }</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* Keep track of the last set hostname */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; g_free (priv-&gt;last_hostname);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp; priv-&gt;last_hostname = g_strdup (name);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; priv-&gt;changing_hostname = <span style="color: rgba(0, 0, 255, 1)">TRUE</span>;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; _LOGI (LOGD_DNS, <span style="color: rgba(0, 96, 128, 1)">"set-hostname: set hostname to '%s' (%s)"</span>, name, msg);</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; <span style="color: rgba(0, 128, 0, 1)">/* Ask NMSettings to update the transient hostname using its</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)"><span style="color: rgba(0, 128, 0, 1)">&nbsp;&nbsp;&nbsp;&nbsp; * systemd-hostnamed proxy */</span></pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp; nm_hostname_manager_set_transient_hostname (priv-&gt;hostname_manager,</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name,</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; settings_set_hostname_cb,</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(244, 244, 244, 1)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_object_ref (self));</pre><pre style="border-style: none; overflow: visible; font-size: 11pt; font-family: &quot;Courier New&quot;, courier, monospace; width: 100%; color: rgba(0, 0, 0, 1); padding: 0; direction: ltr; text-align: left; margin: 0; line-height: 11pt; background-color: rgba(255, 255, 255, 1)">}</pre></div></div>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><img title="clip_image003" style="border: 0; background-image: none; padding-top: 0; padding-left: 0; display: inline; padding-right: 0" border="0" alt="clip_image003" src="https://img2018.cnblogs.com/blog/73542/201911/73542-20191106095818657-1063053044.png" width="619" height="324"></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><img title="clip_image004" style="border: 0; background-image: none; padding-top: 0; padding-left: 0; display: inline; padding-right: 0" border="0" alt="clip_image004" src="https://img2018.cnblogs.com/blog/73542/201911/73542-20191106095819597-1043298489.png" width="651" height="401"></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: normal; text-indent: 0; mso-layout-grid-align: none" align="left"><span lang="X-NONE" style="line-height: normal; mso-font-kerning: 0pt; mso-ansi-language: x-none; mso-fareast-font-family: 宋体"><font face="Times New Roman"><font style="font-size: 12pt" color="#000000">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 0; mso-layout-grid-align: none" align="left"><b><span style="line-height: 27pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 18pt" color="#000000">参考资料:</font></font></span></b></p>
<p class="MsoNormal" style="word-break: normal; margin: 0; line-height: 16pt; text-indent: 21pt; mso-layout-grid-align: none" align="left"><u><span style="line-height: 16pt; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 等线; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-ansi-language: zh-cn"><font face="宋体"><font style="font-size: 10.5pt" color="#0000ff">https://github.com/NetworkManager/NetworkManager/blob/master/src/nm-policy.c</font></font></span></u></p>

</div>
<div id="MySignature" role="contentinfo">
    <div id="KerryCodeSignature">
<div>
<img src="https://images.cnblogs.com/cnblogs_com/kerrycode/1913302/o_240731062102_kerrycode.png" height="120" width="500">
</div>
<div>
<b>扫描上面二维码关注我</b>
</div>
<div>如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!</div>
<div>本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.</div>
</div><br><br>
来源:https://www.cnblogs.com/kerrycode/p/11803373.html
頁: [1]
查看完整版本: Centos 7修改hostname浅析