YAZONG 我的开源

(科学上网)LINUX终端Clash连接[无GUI]

  , ,
0 评论0 浏览

推荐一个科学上网的地址:”https://dashboard.zrj222.com/”。

警告:不要非法使用

购买后看”使用文档-LINUX终端Clash连接[无GUI]”(仅终端内使用)

image.png

(注意:下载的windows科学上网的软件里面的代理端口在这里是不能使用的。)

image.png

下述机器的初始化配置参考:"(虚拟机)Centos7.X-64bit操作系统初始化配置"

#仅终端内使用

#服务器基础信息
[root@kxsw-1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@kxsw-1 ~]# uname -a
Linux kxsw-1 3.10.0-1160.49.1.el7.x86_64 #1 SMP Tue Nov 30 15:51:32 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@kxsw-1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
10.0.0.100
[root@kxsw-1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37
172.16.1.100
[root@kxsw-1 ~]# cat /etc/hosts
127.0.0.1   localhost
172.16.1.100 kxsw-1
#1、获取Clash
#下不下来,直接黏贴地址下载到磁盘clash-linux-amd64-v1.10.6.gz
#若国内不能用 wget 获取github的文件,请自行更改链接为任意国内反代地址。 比如把下面的地址从 github.com 修改为 hub.fastgit.org 或者 https://ghproxy.com/https://github.com/仓库名/xxxx
[root@kxsw-1 ~]# mkdir ~/clash
[root@kxsw-1 ~]# cd clash/
[root@kxsw-1 clash]# wget https://ghproxy.com/https://github.com/Dreamacro/clash/releases/download/v1.10.6/clash-linux-amd64-v1.10.6.gz

[root@kxsw-1 clash]# gunzip -d clash-linux-amd64-v1.10.6.gz
[root@kxsw-1 clash]# chmod +x ./*
[root@kxsw-1 clash]# ll
total 8788
-rwxr-xr-x 1 root root 8998912 May  7 21:21 clash-linux-amd64-v1.10.6
#2、获取所有SS协议连接节点连接
#作用:前往此链接,复制配置到 ~/clash 里,即:config.yaml。
#下不下来,直接黏贴地址下载到磁盘config.yaml,新建notepad以yaml格式存储,记得先把文本格式设置为UTF8再黏贴进来,否则传到服务器是乱码
#这里要复制你自个文档中的链接,自己的链接千万不要暴露出去!
[root@kxsw-1 clash]# wget -O config.yaml 'https://convert.szlatteart.com/sub?XX'
#下不下来,直接黏贴地址下载到磁盘Country.mmdb
[root@kxsw-1 clash]# wget https://fastly.jsdelivr.net/gh/Dreamacro/maxmind-geoip@release/Country.mmdb
#如果需长期使用,请搜索如何使用 screen 或者 daemon 模式
[root@kxsw-1 clash]# setsid ./clash-linux-amd64-v1.10.6 -d ~/clash
#3、连接
#如果只希望在当前终端内使用代理,可以直接用 export
#另外关于其他程序的使用,你需要在程序内设置socks5代理为 127.0.0.1 7890 才可以。如果你用的程序没有提供代理设置,那。。摊手。
[root@kxsw-1 clash]# export http_proxy=http://127.0.0.1:7890 
[root@kxsw-1 clash]# export https_proxy=http://127.0.0.1:7890
#注意这行是必须执行的
[root@kxsw-1 clash]# export no_proxy="localhost, 127.0.0.1"
[root@kxsw-1 clash]# vim /etc/profile
export http_proxy=http://kxsw-1:7890
export https_proxy=http://kxsw-1:7890
#注意这行是必须执行的
export no_proxy="localhost, 127.0.0.1"
[root@kxsw-1 clash]# source /etc/profile
4、在其他节点测试:
#每个节点都要设置
[root@node-X clash]# vim /etc/profile
export http_proxy=http://kxsw-1:7890
export https_proxy=http://kxsw-1:7890
#注意这行是必须执行的
export no_proxy="localhost, 127.0.0.1"
[root@node-X clash]# source /etc/profile

#不hang住,正常显示和响应即可
[root@node-X ~]# curl www.google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/&ust=1667202569571924&usg=AOvVaw2j8VBjV2UKsrLTrHPPs7mb">here</A>.
</BODY></HTML>
[root@node-X ~]# curl twitter.com
[root@node-X ~]# curl www.baidu.com

#可以发现在其他”node-X”节点访问外网时,代理机器”kxsw-1”打印的日志:

image.png

#5、查询环境变量
[root@kxsw-1 clash]# env|grep -I proxy
http_proxy=http://kxsw-1:7890
https_proxy=http://kxsw-1:7890
no_proxy=localhost, 127.0.0.1

[root@node-3 ~]# env|grep -I proxy
http_proxy=http://kxsw-1:7890
https_proxy=http://kxsw-1:7890
no_proxy=localhost, 127.0.0.1

#6、去除环境变量
[root@kxsw-1 clash]# unset XX
[root@kxsw-1 clash]# env|grep -I proxy

#7、杀掉端口
lsof -i :7890
kill -9 pid号

#8、References
https://github.com/yuanlam/Clash-Linux

标题:(科学上网)LINUX终端Clash连接[无GUI]
作者:yazong
地址:https://blog.llyweb.com/articles/2022/11/01/1667236018028.html