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

参考

相关推荐
vx1530278236230 分钟前
‌CDGP|数据治理:探索企业数据有序与安全的解决之道
大数据·运维·网络·cdgp·数据治理
GottdesKrieges1 小时前
OceanBase性能关键参数配置最佳实践
linux·oceanbase
努力学习的小廉1 小时前
深入了解linux系统—— 自定义shell
linux·运维·chrome
1024小神1 小时前
tauri-plugin-store 这个插件将数据存在本地电脑哪个位置
运维·服务器
孞㐑¥1 小时前
Linux之进程概念
linux·c++·经验分享·笔记
Fanmeang2 小时前
BGP选路原则实验案例
运维·网络·华为·bgp·路由选路·路由选路原则·route-policy
Lw老王要学习2 小时前
Linux架构篇、第三章_2_Linux服务器监控与NGINX优化
linux·运维·服务器·nginx·架构·云计算
极小狐2 小时前
如何从极狐GitLab 容器镜像库中删除容器镜像?
java·linux·开发语言·数据库·python·elasticsearch·gitlab
极小狐2 小时前
如何使用极狐GitLab 软件包仓库功能托管 terraform?
linux·运维·git·ssh·gitlab·terraform
mixboot2 小时前
CentOS 7.9 安装详解:手动分区完全指南
linux·centos·手动分区