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

参考

相关推荐
dessler2 分钟前
代理服务器-LVS的3种模式与调度算法
运维·服务器·网络·算法·nginx·tomcat·lvs
Lw老王要学习19 分钟前
Linux容器篇、第二章_01Ubuntu22 环境下 KubeSphere 容器平台高可用搭建全流程
linux·运维·服务器·k8s·kubesphere·容器化
張萠飛1 小时前
Linux下如何使用shell脚本导出elasticsearch中某一个index的数据为本地csv文件
linux·运维·elasticsearch
电商API_180079052472 小时前
构建高效可靠的电商 API:设计原则与实践指南
运维·服务器·爬虫·数据挖掘·网络爬虫
晓枫-迷麟2 小时前
【nano与Vim】常用命令
linux·编辑器·vim
tianyuanwo3 小时前
Ansible自动化运维全解析:从设计哲学到实战演进
运维·自动化·ansible
LucienShui3 小时前
Webhook 配置备忘
linux·运维·webhook
LanLance3 小时前
ES101系列09 | 运维、监控与性能优化
java·运维·后端·elasticsearch·云原生·性能优化·golang
Clownseven3 小时前
“轻量应用服务器” vs. “云服务器CVM”:小白入门腾讯云,哪款“云机”更适合你?(场景、配置、价格对比解析)
运维·服务器·腾讯云
Leo.yuan4 小时前
API是什么意思?如何实现开放API?
大数据·运维·数据仓库·人工智能·信息可视化