配置v2ray代理客户端

# 安装v2ray
pacman -S v2ray

#编辑代理配置文件
vim /etc/v2ray/config.json

#启动v2ray
systemctl start v2ray

配置Privoxy

Privoxy 是一个 HTTP 协议过滤代理,常结合 Tor 使用。Privoxy 是有着先进的过滤能力和保护隐私的代理工具,它可以过滤网页内容,管理cookies,控制访问,除广告、横幅、弹出窗口等等,它同时支持单系统和多用户网络。

当用户直接使用 SOCKS 代理访问网络时,浏览器会泄漏 DNS 请求,降低匿名性,这时应该使用 Privoxy。

# 安装privoxy
pacman -S privoxy

# 配置转发规则
vim /etc/privoxy/config

# 找到 forward-socks5t 一行反注释
# 更改其值为v2ray代理监听的地址
# 注意最后面有一个空格和点号
forward-socks5t   /               127.0.0.1:10808 .

# 启动privoxy
systemctl start privoxy

在使用 privoxy 对 sock5 等代理协议进行转发成 http 的时候 forward-socks5 和 forward-socks5t 区别虽然不是很大,但是有时候却非常头疼,只能 GET 不能 POST。经过排查发现,forward-socks5 的 DNS 解析会在远程服务器上进行,而 forward-socks5t 却不会,这就导致使用后者访问境外网站的时候 ,国内 DNS 无法解析境外网址的情况,从而也就不知道去访问哪个IP。一般来说,还是建议使用 forward-socks5。

配置proxychains

有些linux命令行工具没有配置代理的方法, 可以用proxychains强制应用使用代理网络

安装proxychains

修改配置文件/etc/proxychains.conf最后一行

socks5  127.0.0.1 10808

使用proxychains方法, 在命令前加上proxychains, 如

proxychains cargo build
proxychains git clone

设置了proxy环境变量后,proxychain用不了

[modao@modao ~]$ proxychains curl google.com
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.16
[proxychains] Strict chain  ...  127.0.0.1:10808  ...  google.com:80  ...  OK
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
[modao@modao ~]$ export all_proxy=127.0.0.1:8118
[modao@modao ~]$ proxychains curl google.com
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.16
[proxychains] Strict chain  ...  127.0.0.1:10808  ...  127.0.0.1:8118  ...  OK
^C
[modao@modao ~]$ export all_proxy=127.0.0.1:10808
[modao@modao ~]$ proxychains curl google.com
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.16
[proxychains] Strict chain  ...  127.0.0.1:10808  ...  127.0.0.1:10808  ...  OK
^C
[modao@modao ~]$

配置终端代理

写入配置文件,永久生效

在命令行执行,临时生效

export http_proxy="127.0.0.1:8118"
export https_proxy="127.0.0.1:8118"

以上设置,有些场景无法成功代理,比如yay、git 正确的设置方法是:

export http_proxy="http://127.0.0.1:8118"
export https_proxy="http://127.0.0.1:8118"

通过curl www.google.com命令检查是否设置成功。

取消代理设置

unset http_proxy
unset https_proxy

note:通过脚本设置临时代理是不起作用的

有效操作:source ./set.sh. ./set.sh

在UNIX系统中,我们在运行shell程序或系统命令的过程如下:

  • 假设在当前的shell环境下,我们运行ps -f命令
  • 首先,当前的shell会调用fork()命令,产生一个subprocess,该子进程完全复制了父进程的所有环境
  • 之后,当前的shell会调用exec ps -f命令,在新的子进程的环境中运行ps -f 命令。子进程的环境变量会根据新的应用进行调整,并使之运行,当应用完成之后,子进程结束,返回到父进程

配置Git代理

Using git-config

Git reads its configuration from four INI-type configuration files:

  • /etc/gitconfig for system-wide defaults
  • ~/.gitconfig and ~/.config/git/config (since 1.7.12) for user-specific configuration
  • .git/config for repository-specific configuration

配置Git http/https代理

~/.config/git/config文件中加入以下配置:

[http]
	proxy = socks5://127.0.0.1:10808

注意,上明配置等同于命令

git config --global http.proxy 'socks5://127.0.0.1:10808'

Git不认https.proxy,设置http.proxy就可以支持 https 了。

配置Git SSH代理

在 ~/.ssh/config 文件中加入以下配置:

Host github.com
HostName github.com
User git
Port 22
ProxyCommand /usr/bin/ncat --proxy 127.0.0.1:10808 --proxy-type socks5 %h %p