Linux服务器使用代理

  1. 首先你需要一个能使用的代理节点,我这里是 xray 的 vless 节点,所以我安装 xray-core 的内核。

这里提供xray 的 x86 服务器下载地址

第一步获取你节点信息,我这里是用了第三方客户端的 JSON 信息,直接复制出来的

写入到config.json文件中,下面的 xray 启动需要这个配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
"log": {
"access": "",
"error": "",
"loglevel": "warning"
},
"inbounds": [
{
"tag": "proxy",
"port": 1089,
"listen": "127.0.0.1", //监听本机
"protocol": "socks", //socks5代理
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"auth": "noauth",
"network": "tcp,udp"
}
},
{
"tag": "proxy-docker",
"port": 1089,
"listen": "172.17.0.1", //监听容器
"protocol": "socks", //socks5代理
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"auth": "noauth",
"network": "tcp,udp"
}
},
{
"listen": "127.0.0.1", //监听本机
"port": 8889,
"protocol": "http", //http代理
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"network": "tcp,udp",
"auth": "noauth"
},
"tag": "http"
},
{
"listen": "172.17.0.1", //监听容器
"port": 8889,
"protocol": "http", //http代理
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"network": "tcp,udp",
"auth": "noauth"
},
"tag": "http-docker"
}
],
"outbounds": [ //outbounds部分,就是根据你自己节点情况修改,如果不知道怎么改,就用第三方客户端导出配置文件,替换一下这一部分就可以了。
{
"_QV2RAY_USE_GLOBAL_FORWARD_PROXY_": false,
"mux": {
"concurrency": 1,
"enabled": null
},
"protocol": "vless",
"sendThrough": "0.0.0.0",
"settings": {
"vnext": [
{
"address": "xxx.com",
"port": 443,
"users": [
{
"encryption": "none",
"id": "xxx-xxxx"
}
]
}
]
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"serverName": "xx.gq"
},
"wsSettings": {
"path": "/xx"
}
},
"tag": ""
}
],
"stats": {}
}
  1. 下载最新的 xray-core 内核
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mkdir /root/xray

cd /root/xray

## 下载最新的xray内核

wget https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-64.zip

## 解压文件

unzip Xray-linux-64.zip

## 运行,自己可以用systemd或者screen等等后台运行

/root/xray/xray run -c /root/xray/config.json // 这里的配置文件就是上面的配置文件

如果不提示什么错误,至少表明软件的运行没什么问题

systemd 后台运行

1
2
3
#编辑配置文件,输入i,进行编辑,按esc退出编辑,:wq保存退出

vim /etc/systemd/system/xray.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#添加下面内容

[Unit]

Description=xray Service

After=network.target nss-lookup.target

[Service]

User=root

CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

NoNewPrivileges=true

ExecStart=/root/xrayu/xray run -c /root/xray/config.json

Restart=on-failure

RestartPreventExitStatus=23

[Install]

WantedBy=multi-user.target

#以上
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#开机自启

systemctl enable xray

#启动

systemctl start xray

#停止

systemctl stop xray

#查看运行状态

systemctl status xray

终端设置代理:

1
2
3
4
#添加环境变量

vim ~/.bashrc
#或者.zshrc或者/etc/profile
1
2
3
4
5
6
7
8
9
#添加,http和socks5这两个选一个,添加或者删掉#注释即可。

export http_proxy="http://127.0.0.1:8080"

export https_proxy="https://127.0.0.1:8080"

#export http_proxy="socks5://127.0.0.1:1080"

#export https_proxy="socks5://127.0.0.1:1080"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#生效

source ~/.bashrc

#或者

source .zshrc

source /etc/profile

#测试

#不管是http还是socks5都是ping不了的。

curl google.com