小编ini*_*_js的帖子

如何使用 Windows WSL 配置路由?这可能吗?

根据 sysctl,我注意到 WSL(Windows 10pro 1709)中似乎启用了 IP 转发。我希望我可以用它在 WSL 上制作一个软件路由器——在同一台物理主机上处理 Hyper-V VM 流量。VM 和主机可以通过共享的 /24 ipv4 子网进行通信。

理想情况下,我想使用 WSL 来配置类似 iptables 的规则,或者使用某种可以重写流量的 RAW 套接字的软件路由器程序。

# on the WSL bash
$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
Run Code Online (Sandbox Code Playgroud)

我的 Windows 主机和 VM 都在 192.168.4.X 中。192.168.4.215 是主机。192.168.4.228 是虚拟机。

我已向 Windows 防火墙添加了一条规则,以允许该子网上的每个传入 TCP 端口,并通过传输由 WSL 主机提供服务并由 VM 下载的网页来测试连接性。(例如python -m SimpleHTTPServer在 wsl 中运行并 curl http://192.168.2.215在 vm 上使用)

我已将 Windows 主机添加为 VM 内的默认网关:

# route add default gw 192.168.4.215
# route -n
Kernel IP routing …
Run Code Online (Sandbox Code Playgroud)

networking windows-firewall virtual-machine windows-subsystem-for-linux

6
推荐指数
0
解决办法
5366
查看次数