网站收录是什么意思?,制作网站费用明细,男女做暖暖的试看网站漫画,做网站重要标签在Windows 安装的Ubuntu#xff0c;如何修改主机名。有列了两种方法#xff0c;提供给大家参照。 文章目录 方法一#xff1a;hostname指令修改方法二#xff1a;修改配置文件修改hostnanmewsl.conf 文件配置选项推荐阅读 方法一#xff1a;hostname指令修改
hostname指…在Windows 安装的Ubuntu如何修改主机名。有列了两种方法提供给大家参照。 文章目录 方法一hostname指令修改方法二修改配置文件修改hostnanmewsl.conf 文件配置选项推荐阅读 方法一hostname指令修改
hostname指令修改hostname
sudo hostname test修改后需要reboot我们可以通过执行特定指令查看是否有修改
hostname可以看到hostname已经暂时修改但
mirrorY2040001-PC:~$ hostname
test方法二修改配置文件修改hostnanme
打开 /etc/wsl.conf wsl.conf这个文件如果这个文件不存在则新建
sudo vi /etc/wsl.confhostname Ubuntu22
generateHosts falsehostname Ubuntu22将更新/etc/hostname中的主机名generateHosts false 将阻止WSL自动生成/etc/hosts文件。否则在重新启动Ubuntu时hosts文件更改将被覆盖会出现报错sudo: unable to resolve host test: Name or service not known
sudo vi /etc/hosts红框处修改为新的hostname
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts false
127.0.0.1 localhost
127.0.1.1 Ubuntu22.localdomain Ubuntu22 127.0.0.1 localhost修改完成后保存并退出。关闭子系统或者重新运行子系统 修改不会立即生效关闭子系统后必须等待~8秒。必须等待8秒的原因官方解释如下
If you launch a distribution (ie. Ubuntu), modify the wsl.conf file, close the distribution, and then re-launch it. You might assume that your changes to the wsl.conf file have immediately gone into effect. This is not currently the case as the subsystem could still be running. You must wait ~8 seconds for the subsystem to stop before relaunching in order to give enough time for your changes to be picked up.
可以在power shell中执行wsl --list --running查看子系统是否仍然还在运行。
PS C:\Users\Administrator wsl --list --running如果想要立即停止可以执行如下
wsl -t Ubuntu或者
wsl --shutdown重新开机子系统验证hostname修改成功。
mirrorUbuntu22:~$ hostname
Ubuntu22
mirrorUbuntu22:~$wsl.conf 文件配置选项
wsl.conf 文件有一些配置选项大家可以根据自己需要参考
# Automatically mount Windows drive when the distribution is launched
[automount]# Set to true will automount fixed drives (C:/ or D:/) with DrvFs under the root directory set above. Set to false means drives wont be mounted automatically, but need to be mounted manually or with fstab.
enabled true# Sets the directory where fixed drives will be automatically mounted. This example changes the mount location, so your C-drive would be /c, rather than the default /mnt/c.
root /# DrvFs-specific options can be specified.
options metadata,uid1003,gid1003,umask077,fmask11,caseoff# Sets the /etc/fstab file to be processed when a WSL distribution is launched.
mountFsTab true# Network host settings that enable the DNS server used by WSL 2. This example changes the hostname, sets generateHosts to false, preventing WSL from the default behavior of auto-generating /etc/hosts, and sets generateResolvConf to false, preventing WSL from auto-generating /etc/resolv.conf, so that you can create your own (ie. nameserver 1.1.1.1).
[network]
hostname DemoHost
generateHosts false
generateResolvConf false# Set whether WSL supports interop processes like launching Windows apps and adding path variables. Setting these to false will block the launch of Windows processes and block adding $PATH environment variables.
[interop]
enabled false
appendWindowsPath false# Set the user when launching a distribution with WSL.
[user]
default DemoUser# Set a command to run when a new WSL instance launches. This example starts the Docker container service.
[boot]
command service docker start推荐阅读 Ubuntu挂载NFS(Network File System) 怎么解决权限不一致的问题 Ubuntu镜像源cn.arichinve.ubuntu.com不可用原因分析和解决 Windows 11安装Ubuntu 实战教程 PowerShell无人参与安装最新版本SQL Server Management Studio (SSMS) VRRP虚拟路由器冗余协议标准协议工作机制与优势介绍