wsl1 ubuntu通过宿主机代理连接外网

背景:公司电脑是局域网,通过走代理来连接外网

wsl1 ubuntu想要通过来连接宿主机的局域网代理,访问外网

可以先在ubuntu上测试下走代理的网络,注意不能用ping(ping不走代理),可用curl测试

curl -x http://<your_ip>:<your_port> http://www.baidu.com # <your_ip>:<your_port>更改为宿主机的代理ip和端口

环境变量配置

配置在/etc/profile.d目录下,新建个.sh文件(vim /etc/profile.d/http_proxy.sh

export http_proxy=http://<your_ip>:<your_port> # <your_ip>:<your_port>更改为宿主机的代理ip和端口
export https_proxy=http://<your_ip>:<your_port> # <your_ip>:<your_port>更改为宿主机的代理ip和端口

然后,source /etc/profile

注:配置在/etc/profile.d目录,会对所有用户生效;如果配置在~/.bashrc,只会对当前用户生效。

apt换源

中科大镜像的各种源:https://mirrors.ustc.edu.cn/

【重要】换源教程:https://mirrors.ustc.edu.cn/help/ubuntu.html

sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list
sudo sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

一般情况下,将 /etc/apt/sources.list 文件中 Ubuntu 默认的源地址 http://archive.ubuntu.com/ 替换为 http://mirrors.ustc.edu.cn/ 即可。

原版url

http://archive.ubuntu.com/ubuntu/
http://security.ubuntu.com/ubuntu/

换源url

https://mirrors.ustc.edu.cn/ubuntu/

apt安装,测试是否能通外网

sudo su,到root用户

apt update
apt install net-tools # 包含ifconfig
apt install tree
# apt upgrade # 可选

update是更新软件列表,upgrade是更新软件

可能出现的问题:Temporary failure resolving

我的情况是并不需要配置DNS(/etc/resolv.conf/etc/wsl.conf),只要做好前面的操作就可以了。

(可选)最后把/etc/wsl.conf设置如下(这样设置,wsl ubuntu每次重启还是会自动分配不同的网关ip):

[network]
generateResolvConf = true

参考

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nefu-ljw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值