如何将主机名永久更改为debian?

如何将主机名永久更改为debian?

你好 Linux 社区。
我从 Vultr 购买了 VPS 服务,所以这不是安装了 Linux 的家庭独立 PC。我必须处理他们“提供”的所有这些晦涩的控制面板设置。
当我在我付费的 VPS 实例上重新安装操作系统后,问题就出现了。
我已经将kali-linux(这也是我当时的主机名)更改为debian 11.我没有销毁这个 vps 实例。我刚刚重新安装了操作系统。我的IP和以前一样。

在我将操作系统更改为 后debian 11,我还想将主机名更改为debian,这是我的问题的开始。

系统重新安装后,我注意到Vultr的客户面板中有一个特殊的按钮,2更改主机名,所以我确实按下了它,系统很快又重新安装了一次,我希望一切顺利。

在此输入图像描述

当我登录 VPS 并检查/etc/hostname其声明时,它是debian.

rafal@debian:~$ cat /etc/hostname
debian

当我检查时,/etc/hosts它看起来像这样:

rafal@debian:~$ cat /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
127.0.1.1 kali_linux.edu kali_linux
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

我没有任何合格的域名,所以我不知道在 后面放什么127.0.1.1,但我非常确定,我不想kali_linux.edu

在同一行中,在最后,我需要更改kali_linuxdebian.但是当我更改一次后,在 vps 重新启动后,它会恢复为旧值。

我可以看到,有一些注释行引用了这个文件:/etc/cloud/templates/hosts.debian.tmpl,但是当我尝试编辑它(使用 Vim)时,我得到这个:

E325: ATTENTION
Found a swap file by the name "/etc/cloud/templates/.hosts.debian.tmpl.swp"
          owned by: root   dated: Wed Jan 04 19:48:16 2023
         file name: /etc/cloud/templates/hosts.debian.tmpl
          modified: YES
         user name: root   host name: debian
        process ID: 1272
While opening file "/etc/cloud/templates/hosts.debian.tmpl"
             dated: Fri Dec 16 16:50:25 2011

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /etc/cloud/templates/hosts.debian.tmpl"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/etc/cloud/templates/.hosts.debian.tmpl.swp"
    to avoid this message.

我对此一无所知。据我所知,交换文件是当物理 RAM 已满时用于转储 RAM 内存的某些部分的文件。我不知道其他文件的交换文件是什么:-(

但这个文件/etc/cloud/templates/hosts.debian.tmpl看起来像这样:

## template:jinja
{#
This file (/etc/cloud/templates/hosts.debian.tmpl) is only utilized
if enabled in cloud-config.  Specifically, in order to enable it
you need to add the following to config:
   manage_etc_hosts: True
-#}
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
{# The value '{{hostname}}' will be replaced with the local-hostname -#}
127.0.1.1 {{fqdn}} {{hostname}}
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

所有这些混乱的影响是,我遇到了这个错误sudo: unable to resolve host debian: Name or service not known.

rafal@debian:~$ sudo apt install unattended-upgrades
sudo: unable to resolve host debian: Name or service not known
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
unattended-upgrades is already the newest version (2.8).
The following packages were automatically installed and are no longer required:
  gir1.2-packagekitglib-1.0 libappstream4 libdw1 libglib2.0-bin libgstreamer1.0-0 libpackagekit-glib2-18 libstemmer0d libunwind8 packagekit
  packagekit-tools python3-software-properties software-properties-common
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

如何将主机名永久更改为debian

相关内容