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

文章目录

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

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

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

bash 复制代码
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

bash 复制代码
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

bash 复制代码
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

bash 复制代码
http://archive.ubuntu.com/ubuntu/
http://security.ubuntu.com/ubuntu/

换源url

bash 复制代码
https://mirrors.ustc.edu.cn/ubuntu/

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

sudo su,到root用户

bash 复制代码
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):

bash 复制代码
[network]
generateResolvConf = true

参考

相关推荐
linchare2 小时前
linux debian上只装mysql的客户端步骤
linux·mysql·debian
wanhengidc4 小时前
网站服务器都有哪些作用?
运维·服务器·科技·智能手机·云计算
百***75744 小时前
linux上redis升级
linux·运维·redis
顾安r5 小时前
11.22 脚本打包APP 排错指南
linux·服务器·开发语言·前端·flask
Neur0toxin5 小时前
入侵排查_2025/11/23
linux·windows·应急响应
小小编程能手5 小时前
Linux文件编程
linux·运维·服务器
木童6626 小时前
nginx安装步骤详解
linux·运维·服务器·网络·nginx
暴躁的菜鸡6 小时前
Ubuntu安装向日葵
linux·运维·ubuntu
wa的一声哭了6 小时前
Webase部署Webase-Web在合约IDE页面一直转圈
linux·运维·服务器·前端·python·区块链·ssh
Aufidius6 小时前
虚拟机ubuntu存储空间不够如何扩容(扩充根目录)
linux·运维·ubuntu