网络组建与维护论文,温州seo网站推广,重庆好的网站制作公司哪家好,海南专业网站建设定制现状#xff1a;
Window11中拥有自己的代理软件 #xff0c;可以科学上网已在WSL2中安装Ubuntu22.04
需求#xff1a;
Ubuntu-WSL2实现科学上网
实现#xff1a;
参考#xff1a;为 WSL2 一键设置代理
Linux 子系统中的网关指向的是 Windows#xff0c;DNS 服务器指…现状
Window11中拥有自己的代理软件 可以科学上网已在WSL2中安装Ubuntu22.04
需求
Ubuntu-WSL2实现科学上网
实现
参考为 WSL2 一键设置代理
Linux 子系统中的网关指向的是 WindowsDNS 服务器指向的也是 Windows
在 Ubuntu 子系统中通过 cat /etc/resolv.conf 查看 DNS 服务器 IP如下所示IP为10.255.255.254
~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf false
nameserver 10.255.255.254WSL2 中配置的代理要指向 Windows 的 IP
创建一个bash脚本实现代理如下
touch set_proxy.sh # 创建空白脚本文件
vim set_proxy.sh #编辑
chmod x set_proxy.sh #增加运行权限
./set_proxy.sh # 运行# set_proxy.sh文件内容
host_ip$(cat /etc/resolv.conf |grep nameserver |cut -f 2 -d )
export ALL_PROXYhttp://$host_ip:7897
echo 设置代理成功端口7897请在Windows中打开客户端允许本地局域网请求 /home/user/set_proxy.log # 输出log验证是否开机运行成功
exit 0 Windows 上的代理客户端需要允许来自本地局域网的请求 4.测试配置是否成功
~$ ping google.com
PING google.com (198.18.0.78) 56(84) bytes of data.
64 bytes from 198.18.0.78 (198.18.0.78): icmp_seq1 ttl63 time1.89 ms
64 bytes from 198.18.0.78 (198.18.0.78): icmp_seq2 ttl63 time1.08 ms
64 bytes from 198.18.0.78 (198.18.0.78): icmp_seq3 ttl63 time1.26 ms
64 bytes from 198.18.0.78 (198.18.0.78): icmp_seq4 ttl63 time1.12 ms
64 bytes from 198.18.0.78 (198.18.0.78): icmp_seq5 ttl63 time1.31 ms
64 bytes from 198.18.0.78 (198.18.0.78): icmp_seq6 ttl63 time0.586 ms
64 bytes from 198.18.0.78 (198.18.0.78): icmp_seq7 ttl63 time0.735 ms设置脚本开启启动
参考Ubuntu开机自启动脚本/命令的几种方案
sudo cp set_proxy.sh /etc/init.d/
sudo update-rc.d set_proxy.sh defaults验证开机启动
重启wsl命令参考如何在 Windows 11 上启动、重新启动或关闭 WSL2
wsl --shutdown
Get-Service LxssManager | Restart-Service
wslping google.com #重启后查看ping谷歌是成功