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

参考

相关推荐
正在努力的小河37 分钟前
Linux设备树简介
linux·运维·服务器
荣光波比39 分钟前
Linux(十一)——LVM磁盘配额整理
linux·运维·云计算
小晶晶京京1 小时前
day35-负载均衡
运维·网络·网络协议·学习·负载均衡
LLLLYYYRRRRRTT1 小时前
WordPress (LNMP 架构) 一键部署 Playbook
linux·架构·ansible·mariadb
轻松Ai享生活1 小时前
crash 进程分析流程图
linux
拾心213 小时前
【运维进阶】LNMP + WordPress 自动化部署实验
运维·自动化·ansible·mariadb
大路谈数字化3 小时前
Centos中内存CPU硬盘的查询
linux·运维·centos
luoqice4 小时前
linux下查看 UDP Server 端口的启用情况
linux
倔强的石头_5 小时前
【Linux指南】动静态库与链接机制:从原理到实践
linux
赏点剩饭7785 小时前
linux中的hostpath卷、nfs卷以及静态持久卷的区别
linux·运维·服务器