解决国内Linux网络原因无法拉取包和相关依赖的问题

声明:本文主要使用github项目gg,项目地址:https://github.com/gblaowang-i/gg

gg 是一个命令行工具,可在 Linux 环境下对任意命令进行一键代理,而无需安装 v2ray 等其他工具。

你只需要在想代理的命令之前添加 gg 即可,例如: gg python -m pip install torch

优势

相比较于 proxychains 或 graftcp,go-graft 拥有以下优势:

  1. gg 下载即用,不需要安装任何额外的工具。
  2. 支持 UDP,从而有效应对 DNS 污染。
  3. 支持 Go 语言编写的程序。见 applications built by Go can not be hook by proxychains-ng 。

安装

运行如下命令下载安装 go-graft 最新的版本:

sudo sh -c "$(curl -L https://github.com/mzz2017/gg/raw/main/release/go.sh)"

不使用 sudo 时,gg 将会安装到用户目录。如果安装完毕后 gg 命令运行 失败,请检查 $PATH.

你也可以创建一个到 /usr/bin 的软链接。

例如:

sudo ln -s /usr/local/bin/gg /usr/bin/gg

测试安装是否成功:

$ gg --version 
gg version 0.1.1

使用方法

配置订阅地址:

gg config -w subscription='https://example.com/path/to/sub'

克隆 linux 仓库来试试效果:

gg git clone --depth=1 https://github.com/torvalds/linux.git

输出:

Cloning into 'linux'...
...
Receiving objects: 100% (78822/78822), 212.19 MiB | 7.04 MiB/s, done.
Resolving deltas: 100% (7155/7155), done.

或者直接代理整个 shell session:

gg bash

git clone --depth=1 https://github.com/torvalds/linux.git
curl ipv4.appspot.com

临时使用

使用节点的分享链接

# 如果你之前没有写过配置项,将会提示你输入节点链接。 
gg wget -O frp.tar.gz https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz
Enter the share-link of your proxy: ********
...
Saving to: ‘frp.tar.gz’
frp.tar.gz 100%[=====================================================>] 8.44M 12.2MB/s in 0.7s    
2021-12-06 09:21:08 (12.2 MB/s) - ‘frp.tar.gz’ saved [8848900/8848900]

或者显式地使用 --node:

gg --node ss://[email protected]:17247 speedtest
Retrieving speedtest.net configuration...
Testing from Microsoft (13.xx.xx.xx)...
...
Hosted by xxx: 55.518 ms
Testing download speed................................................................................
Download: 104.83 Mbit/s
Testing upload speed......................................................................................................
Upload: 96.35 Mbit/s

使用订阅地址

默认情况下 gg 会从你的订阅中自动挑选第一个可用的节点:

gg --subscription https://example.com/path/to/sub docker pull caddy
Using default tag: latest
latest: Pulling from library/caddy
97518928ae5f: Pull complete
23ccae726125: Pull complete
3de6a61c89ac: Pull complete
39ed957bdc00: Pull complete
0ae44c2d42dd: Pull complete
Digest: sha256:46f11f4601ecb4c5a37d6014ad51f5cbfeb92b70f5c9ec6c2ac39c4c1a325588
Status: Downloaded newer image for caddy:latest
docker.io/library/caddy:latest

也可以手动选择节点:

gg --subscription https://example.com/path/to/sub --select curl ipv4.appspot.com
WARN[0000] Test nodes...
Use the arrow keys to navigate: ↓ ↑ → ←  and / toggles search
Select Node
  ? [200Mbps] LoadBalance (323 ms)
    [200Mbps] LoadBalance Trojan (448 ms)
    [30M] CN2-US Cera (560 ms)
    [1Gbps] 4837-US (781 ms)
    [10Gbps] CN2-DE (811 ms)
    [300Mbps] Macau (1023 ms)
    [300Mbps] IPv6 LoadBalance (-1 ms)
↓   [1Gbps] RackNerd (-1 ms)

--------- Detail ----------
Name:               [200Mbps] LoadBalance
Protocol:           shadowsocks
Support UDP:        true
Latency:            323 ms

长期使用

可以使用 -w 来写入配置项:

设置订阅地址:

gg config -w subscription=https://example.com/path/to/sub gg curl ipv4.appspot.com

设置节点链接:

gg config -w node=vmess://MY_VMESS_SERVER_SHARE_LINK
gg curl ipv4.appspot.com

列出所有配置项:

gg config
node=
subscription.link=https://example.com/path/to/sub
subscription.select=first
subscription.cache_last_node=true
cache.subscription.last_node=trojan-go://MY_TROJAN_GO_SERVER_SHARE_LINK
no_udp=false
test_node_before_use=true

清除、重置某个特定配置项:

gg config -u node

读取某个特定配置项:

gg config node

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注