在Linux中,主机名是分配给计算机的名称,通常在网络环境中。主机名用于标识网络上的计算机,并可用于将域名解析为 IP 地址。
在 Debian 11 上更改主机名
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update sudo apt upgrade</span>
第 2 步。检查当前主机名。
更改主机名的第一步是检查系统的当前主机名。您可以通过打开终端窗口并键入以下命令来执行此操作:
<span class="pln">hostnamectl</span>
系统的主机名存储在名为 的文件中。要更改主机名,我们首先需要使用喜欢的文本编辑器打开主机名文件:/etc/hostname
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">hostname</span>
将当前主机名值替换为要分配的新所需名称。例如:
<span class="pln">debian</span><span class="pun">-</span><span class="pln">meilana</span>
保存更改并退出文本编辑器,然后重新启动以应用您对 Debian 设备的主机名所做的更改:
<span class="pln">reboot</span>
第 4 步。验证新主机名。
重新启动系统后,可以使用以下命令验证是否已设置新主机名:
<span class="pln">hostnamectl</span>
输出:
<span class="typ">Static</span><span class="pln"> hostname</span><span class="pun">:</span><span class="pln"> debian</span><span class="pun">-</span><span class="pln">meilana </span><span class="typ">Icon</span><span class="pln"> name</span><span class="pun">:</span><span class="pln"> computer</span><span class="pun">-</span><span class="pln">vm </span><span class="typ">Chassis</span><span class="pun">:</span><span class="pln"> vm </span><span class="typ">Machine</span><span class="pln"> ID</span><span class="pun">:</span><span class="pln"> g0detzd8352c404898f47e005627888 </span><span class="typ">Boot</span><span class="pln"> ID</span><span class="pun">:</span> <span class="lit">9a12f2136ba74g0detz8bc83786888</span> <span class="typ">Virtualization</span><span class="pun">:</span><span class="pln"> kvm </span><span class="typ">Operating</span> <span class="typ">System</span><span class="pun">:</span> <span class="typ">Debian</span><span class="pln"> GNU</span><span class="pun">/</span><span class="typ">Linux</span> <span class="lit">11</span> <span class="pun">(</span><span class="pln">bullseye</span><span class="pun">)</span> <span class="typ">Kernel</span><span class="pun">:</span> <span class="typ">Linux</span> <span class="lit">5.16</span><span class="pun">.</span><span class="lit">0</span><span class="pun">-</span><span class="lit">8</span><span class="pun">-</span><span class="pln">amd64 </span><span class="typ">Architecture</span><span class="pun">:</span><span class="pln"> x86</span><span class="pun">-</span><span class="lit">64</span>
感谢您使用本教程在 Debian 11 Bullseye 上设置或更改主机名。如需更多帮助或有用信息,我们建议您查看 Debian 官方网站。