Cloud servers are too expensive, and you can’t afford a small server? Look at here!
1. Switch WSL2 into mirror mode #
Create a .wslconfig
file in the user directory of windows system, and the configuration content is as follows
[wsl2]
networkingMode=mirrored # Automatic port forwarding, windows and WSL will share the same adress (127.0.0.1)
dnsTunneling=true
firewall=true
autoProxy=true
[experimental]
# sparseVhd = true
autoMemoryReclaim=gradual
The most important item is networkingMode=mirrored
, so that the ipv6 adress will also be the same.
2. Configure WSL2 SSH Server #
sudo nvim /etc/ssh/sshd_config
You may need to change the Port to a non-22 port (the operator may block these ports of home broadband by default)
Some key configurations:
# Listen IPv6
ListenAddress ::
# Use PublicKey
PubkeyAuthentication yes
# No Password
PasswordAuthentication no
Then, configure your ~/.ssh/authorized_keys
. Fill your SSH publick key into it.
3. Configure Windows Firewall #
Windows Firewall with Advanced Security
->Inbound Rules
->New rule
->Port
to allow TCP connections on the port you are using.
4. Configure WSL2 to start at boot (no user login required) #
In Windows System
Task Scheduler
->创建任务
->√不管用户是否登录都要运行
触发器
->新建
->启动时
->确定
操作
->新建
->程序或脚本
选择wsl.exe(通常在C:\Program Files\WSL\wsl.exe)条件
->所有选项取消勾选设置
->除允许按需执行任务
外,其它全部取消勾选- 完成
5. DDNS #
笔者这里域名用的Cloudflare托管,所以选择cloudflare-ddns这个项目。 **Be sure to configure DDNS, otherwise once the ipv6 changes, the host will be disconnected directly if it is not around. **
6. Other Suggestions #
Windows可以搭配Sunshine和与其配套的Moonlight进行串流,外出再也不需要带笔记本了。笔者使用Android平板进行串流实测体验超乎意料的好。
References #
https://www.ryanshang.com/2024/01/06/WSL2%E8%AE%BE%E7%BD%AE%E9%95%9C%E5%83%8F%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%BC%8F/ https://www.sjdhome.com/blog/post/wsl2-auto-start/