WSL:Windows Subsystem For Linux
前段时间听说WSL2很香,然后试了一下,确实很香......如果你不是一个WEB狗
WSL2的安装我就不具体写了,太简单了,直接看官网教程
0x00 与WSL的区别
WSL1大家应该都很熟悉,WSL2也问世挺久了,我就不详细嗦了,直接看看官网解释的区别:
摘自微软官网
整体上看......这俩完全就不是一个东西嘛:wsl只是一个单纯的shell,wsl2简直就是一台虚拟机
WSL2从OS层实现了独立,不再与宿主机共享OS,解决了许多二进制狗的蜜汁BUG,但是这种独立性给WEB狗创造了更多的烦恼
0x01 主要问题
1)服务不通
最主要的问题还是网络层与宿主机不互通:
微软官方说明
ifconfig
一下你会惊奇的发现它没有192
网段地址:
ifconfig
再来看看 WSL2 “独一无二的IP地址的虚拟化以太网适配器”:
WSL2:https://blog.csdn.net/swordsm/article/details/107948497
果然很复杂。再看一眼昔日称霸一方的WSL1的网络拓扑:
WSL1:https://blog.csdn.net/swordsm/article/details/107948497
两图对比,发现WSL1使用的是宿主机的网络,可以直接理解为一台机器,在配置上过于简单,但正因为网络共享,很多应用不能在windows和Linux中同时运行(比如Windows的phpstudy和Linux的docker)
WSL2网络层使用了独立的虚拟网卡,与宿主机进行桥接,网络上实现了独立,但是也造成了麻烦,比如本地服务不互通:
比如内网请求被防火墙干掉:
wsl2 ping 宿主机被拦截
宿主机 ping wsl2 能 ping 通
可能是WD把这个网桥干掉了吧......
2)IPV6
没有IPV6
,失去了免流的梦想......
微软,不愧是您
0x02 解决方案
IPV6
的问题没法解决,干脆忘了它吧,等微软开发下一代产品
Linux请求被拦截的问题......关闭专用网络防火墙可以解决:(确实是WD把这个网桥干掉了)
关闭专用网络防火墙
然后终于ping通了
网络问题大致有两种解决方案:直接localhost或者手动配置端口转发
localhost大概是微软留下的最后的希望,在不能使用127.0.0.1
的情况下,localhost可以直接访问本地服务
这里直接跑了一个DVWA
端口转发可以直接参考官方文档,在宿主机的Powershell中配置:
netsh interface portproxy show all
# 查看转发
netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=192.168.101.100
# 添加转发
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=8000
# 删除转发
0x03 其他问题
Docker Docker Docker!
也可能是我发行版的问题,在运行docker的时候一直报错,一直启动不了:
Chain OUTPUT (policy ACCEPT)
target prot opt source destination`, error: exit status 4
INFO[2020-10-26T18:26:49.534239700+08:00] stopping event stream following graceful shutdown error="<nil>" module=libcontainerd namespace=moby
INFO[2020-10-26T18:26:49.534502600+08:00] stopping event stream following graceful shutdown error="context canceled" module=libcontainerd namespace=plugins.moby
INFO[2020-10-26T18:26:49.534542500+08:00] stopping healthcheck following graceful shutdown module=libcontainerd
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables --wait -t nat -N DOCKER: iptables v1.8.5 (nf_tables): CHAIN_ADD failed (No such file or directory): chain PREROUTING
(exit status 4)
主要错误原因:
iptables v1.8.5 (nf_tables): CHAIN_ADD failed (No such file or directory): chain PREROUTING
docker.io
用iptables
初始化NAT网络,而Debian buster
使用 nftables
而不是 iptables
,导致dockerd
不能正常完成NAT初始化,出错退出。
那么正确的解法应该就是强制使用iptables进行初始化:
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
# 重启docker
sudo service docker restart
然后就能跑了......
其他的BUG可能忘记了,下次想起来再写
https://blog.csdn.net/dqwjack/article/details/107699985
https://docs.microsoft.com/zh-cn/windows/wsl/compare-versions
https://blog.csdn.net/swordsm/article/details/107948497
Reference
"May there be enough clouds, to make a beautiful sunset."
Comments | NOTHING