How to change hostname on debian
<h1 class="entry-title">How to change hostname on Debian 10 Linux</h1><p><span class="last-updated">last updated July 13, 2019 <span class="cat-links">in <span class="screen-reader-text">CategoriesDebian / Ubuntu, Linux</span></span></span></p>
<div class="entry-content">
<p> </p>
<div class="my_story"><img src="https://www.cyberciti.biz/media/new/category/old/debianlogo.gif"></div>
<span class="drop_cap"><span class="drop_cap">How do I change the hostname of a Debian Linux 10 “Buster” operating system permanently using the command line tools?<br><span><br>You can use the hostnamectl command or hostname command to display or set the Debian Linux system’s host name. In this tutorial, you will learn how to change your hostname on Debian Linux.</span></span></span>
<p> </p>
<h2>Change hostname on Debian 10 Linux</h2>
<ol>
<li>Login to your server: <kbd>ssh user@server-name</kbd></li>
<li>Become a root user using either <kbd>sudo -s</kbd> or <kbd>su -</kbd></li>
<li>To set the hostname to server1, run: <kbd>hostnamectl set-hostname server1</kbd></li>
<li>Edit the file /etc/hosts and update entries: <kbd>vi /etc/hosts</kbd></li>
<li>Verify it by running the <kbd>hostnamectl</kbd> command again.</li>
</ol>
<p>Let us see all commands in details.</p>
<h2>Display the current hostname for Debian Linux</h2>
<p>Simply run the following command:<br><code>hostnamectl</code></p>
<span class="drop_cap"><span class="drop_cap"><span><img class="size-full wp-image-148073 lazyload" alt="View the current hostname for Debian Linux 10" width="599" height="355" data-src="https://www.cyberciti.biz/media/new/faq/2019/07/View-the-current-hostname-for-Debian-Linux-10.png">The current hostname is set to localhost</span></span></span>
<h2>Change the hostname on Debian 10</h2>
<p>Now you know how to view the current hostname. It is time to change it as per your needs. A hostname is nothing but a name that identifies your Debian box on a network. Typically for the server, you set it as FQDN (fully qualified domain name) such as server1.cyberciti.biz. The syntax is as follows:<br><code>hostnamectl set-hostname {name-here}</code><br>For example, to change the system hostname to deb10.cyberciti.biz in Debian 10, you can use the following command:<br><code>sudo hostnamectl set-hostname deb10.cyberciti.biz</code><br>Next, edit the /etc/hosts file, run:<br><code>vi /etc/hosts</code><br>Find all references to oldname and replace with newname except for the following entries:</p>
<pre>127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters</pre>
<p>For example:</p>
<pre>127.0.0.1 localhost
192.168.2.100 deb10.cyberciti.biz
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters</pre>
<p>Save and close the file.</p>
<h2>Verify the change</h2>
<p>How do you know that hostname was successfully changed? You use the same command without any arguments. In other words, type the following command:<br><code>hostnamectl</code><br><img class="aligncenter size-full wp-image-148074 lazyload" alt="Change hostname on Debian 10 Linux Buster" width="599" height="335" data-src="https://www.cyberciti.biz/media/new/faq/2019/07/Change-hostname-on-Debian-10-Linux-Buster.png"></p>
<h3>Set a particular pretty host name</h3>
<p>The syntax is:<br><code>hostnamectl set-hostname "Vivek's Thinkpad" --pretty</code></p>
<h2>Changing Debian host names remotely using ssh</h2>
<p>From your Linux desktop, run:<br><code>hostnamectl set-hostname -H @hostname<br>hostnamectl set-hostname {new_name_here} -H root@192.168.2.10<br>hostnamectl set-hostname www42.nixcraft.com -H root@192.168.2.10</code><br>The hostnamectl tool will use SSH to connect to the remote system. One can see help page by typing:<br><code>hostnamectl --help</code><br>Sample help page:</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="code">
<pre class="ini">hostnamectl COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=HOSTOperate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host
See the hostnamectl(1) man page for details.</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Conclusion</h2>
<p>On Debian Linux hostnamectl command used to query and change the system hostname and related settings. For more information see the man page here.</p>
<p> </p>
<div class="share-social"><span class="share-label">SHARE ON Facebook Twitter</span></div>
</div><br><br>
来源:https://www.cnblogs.com/mouseleo/p/12050730.html
頁:
[1]