linux中使用clash代理

本机环境:ubuntu16

安装代理工具(这里使用clash)

可以手动下载解压,下载地址:https://github.com/Dreamacro/clash

也可以直接使用命令行,演示如下:

sh 复制代码
user@localhost:~$ curl https://glados.rocks/tools/clash-linux.zip -o clash.zip #下载Clash

user@localhost:~$ unzip clash.zip

user@localhost:~$ cd clash

user@localhost:~$ curl https://这里填你自己的代理List.yaml > glados.yaml #下载您的终端配置文件

user@localhost:~$ chmod +x ./clash-linux-amd64-v1.10.0

user@localhost:~$ ./clash-linux-amd64-v1.10.0 -f glados.yaml -d .

演示如下表示成功:

sh 复制代码
INFO[0000] HTTP proxy listening  at: [::]:7890
INFO[0000] SOCKS proxy listening at: [::]:7891
INFO[0000] RESTful API listening at: 127.0.0.1:9090

日志提示已经开放了HTTP代理服务端口为7890, SOCK55服务端口为7891.

后面设置其他程序(浏览器/GIT等)通过7890/7891来代理访问网络就可以了。

测试

sh 复制代码
wget google.com

有返回结果即可(不能使用PING)

使用代理

以npm为例,docker image,k8s pod等也类似。

sh 复制代码
user@localhost:~$  npm config set proxy http://127.0.0.1:7890 
user@localhost:~$  npm install pm2 -g 
user@localhost:~$  npm config delete proxy  #取消代理设置

开启全局代理

每次在使用都需要指明代理非常的不方便,设置环境变量后就相当于给系统中全部的进程开启了代理。

部分软件无法使用代理,例如ping,它并不是 TCP 应用,因此无法使用Clash的HTTP/SOCK5代理。

设置临时环境变量(设置永久需要改/ect/profile~/.bachrc/.bash_profile不推荐

修改配置文件添加环境变量如下:不推荐

sh 复制代码
vim ~/.bashrc
# 末尾添加
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
# 生效修改后的配置
source ~/.bashrc

临时环境变量如下:

sh 复制代码
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

常见问题及解决方案

  • 7890端口被占用
    解决:
sh 复制代码
# 查询被占用的端口
# lsof命令 用于查看你进程打开的文件,打开文件的进程,进程打开的端口(TCP、UDP)。
# linux中万物皆为文件,进程文件也有端口
sudo lsof -i :7890
# kill
kill 7890 -9 pid
  • 缺少MMDB文件

    kill进程,重启即可

  • 服务器无法正常访问网络

    很有可能是开启了代理,但是没启动代理软件clash

  • 自己的代理服务器list有错

    看是否真的保存在yml文件中了

  • 在保证其他都没问题了还是不能使用代理,则按以下步骤重启

  1. 关闭代理
sh 复制代码
export -n  http_proxy=http://127.0.0.1:7890
export -n https_proxy=http://127.0.0.1:7890
  1. 关闭软件,要保证7890没被占用
sh 复制代码
kill -9 pid
  1. 启动clash软件
sh 复制代码
#启动clash,nohup &后台运行也行
./clash.linux.xxxx
  1. 开启代理
sh 复制代码
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

完毕

相关推荐
哈里谢顿2 小时前
使用kvm创建一台虚拟机
linux
大喵桑丶2 小时前
中间件快速部署(Nginx,Keepalived)
运维·nginx·中间件
hanyi_qwe3 小时前
文本三剑客--awk
linux·运维·服务器
liu****3 小时前
27.epoll(三)
服务器·开发语言·网络·tcp/ip·udp
Caven773 小时前
【Linux 技巧】如何在登录时自动激活 Conda Base 环境
linux·运维·conda
凌寒114 小时前
Linux(Debian)安装、卸载 MySQL
linux·运维·mysql·debian
云飞云共享云桌面4 小时前
如何降低非标自动化工厂的研发软件采购成本
运维·服务器·网络·数据库·性能优化·自动化
七七墨染4 小时前
DotMemory系列:5. 如何实现自动化抓取和应用自托管
运维·c#·自动化
IT小哥哥呀4 小时前
如何从 Windows SSH 进入 VirtualBox Ubuntu 虚拟机——密码认证(逐步指南)
linux·windows·ubuntu·ssh·教程·虚拟机
泰克教育官方账号4 小时前
泰涨知识 | 什么是自动化巡检?
运维·服务器·数据库