栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

将 wsl 1 (centos子系统) 更新为 wsl 2 后 ssh 无法远程连接

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将 wsl 1 (centos子系统) 更新为 wsl 2 后 ssh 无法远程连接

参考

官网对比wsl1和wsl2:
https://docs.microsoft.com/en-us/windows/wsl/compare-versions

说明

将 wsl 1 更新为 wsl 2 用ssh连接的时候,发现原本可用的 ssh 远程连接现在全部不可用?使用的是centOS子系统 依据

官网对比 wsl 1 和 wsl 2 中有说到:

If you rely on a Linux distribution to have an IP address in the same network as your host machine, you may need to set up a workaround in order to run WSL 2. WSL 2 is running as a hyper-v virtual machine. This is a change from the bridged network adapter used in WSL 1, meaning that WSL 2 uses a Network Address Translation (NAT) service for it’s virtual network, instead of making it bridged to the host Network Interface Card (NIC) resulting in a unique IP address that will change on restart. To learn more about the issue and workaround that forwards TCP ports of WSL 2 services to the host OS, see WSL GitHub repository issue 4150, NIC Bridge mode (TCP Workaround).

翻译过来大致内容是

如果您依赖于 Linux 发行版在与主机相同的网络中拥有 IP 地址,则可能需要设置解决方法才能运行 WSL 2。WSL 2 作为 hyper-v 虚拟机运行。这是对 WSL 1 中使用的桥接网络适配器的更改,这意味着 WSL 2 对其虚拟网络使用网络地址转换 (NAT) 服务,而不是将其桥接到主机网络接口卡 (NIC),从而导致在重新启动时将更改的唯一 IP 地址。若要了解有关将 WSL 2 服务的 TCP 端口转发到主机操作系统的问题和变通办法的详细信息,请参阅 WSL GitHub 存储库问题 4150,NIC 桥接模式(TCP 变通办法)。

大概就是 ip 地址可能变了!

在centOS中输入以下命令:
ifconfig
发现IP的确发生变化,那么ssh在连接的时候改一下ip就好了

解决

在centos中输入以下命令查看ip,并复制
ifconfig | grep inet在Xshell中输入如下命令进行远程连接
ssh -p 22 <用户名>@
注:用户名替换为你自己的用户名,ip为上面复制的ip

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/733361.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号