端口映射(一)-- Realm

1、访问Github Release页面, 下载最新版程序包

1
mkdir -p /etc/realm && cd /etc/realm  
1
wget https://github.com/zhboner/realm/releases/download/v2.6.2/realm-x86_64-unknown-linux-gnu.tar.gz

运行上面的命令需要注意下载对应系统的包。

1
tar -zxvf realm-x86_64-unknown-linux-gnu.tar.gz
1
chmod +x realm  

2、编辑配置文件

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
{
"log": {
"level": "warn"
},
"dns": {
"mode": "ipv4_and_ipv6",
"protocol": "tcp_and_udp",
"min_ttl": 0,
"max_ttl": 60,
"cache_size": 5
},
"network": {
"use_udp": true,
"zero_copy": true,
"fast_open": true,
"tcp_timeout": 300,
"udp_timeout": 30,
"send_proxy": false,
"send_proxy_version": 2,
"accept_proxy": false,
"accept_proxy_timeout": 5
},
"endpoints": [
{
"listen": "0.0.0.0:12345",
"remote": "1.1.1.1:54321"
},
{
"listen": "0.0.0.0:1234",
"remote": "2.2.2.2:4321"
}
]
}

测试运行

1
./realm -c config.json

3、设置开机启动(通用方法)

1
vim /etc/systemd/system/realm.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=realm
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
DynamicUser=true
WorkingDirectory=/etc/realm
ExecStart=/etc/realm/realm -c /etc/realm/config.json

[Install]
WantedBy=multi-user.target
1
systemctl enable realm

4、补充内容

Real不仅支持json配置文件,还支持toml配置格式。toml格式配置好像更简单,见下面的模板:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[network]
no_tcp = false
use_udp = true

[[endpoints]] #一对端点,监听本机5000端口的流量并将其转发到1.1.1.1的443端口
listen = "0.0.0.0:5000"
remote = "1.1.1.1:443"

[[endpoints]] #可添加多对端点,可以做负载均衡,可自动解析域名
listen = "0.0.0.0:10000"
remote = "www.google.com:443"
extra_remotes = ["www.bing.com:443", "www.baidu.com:443"]
balance = "roundrobin: 4, 2, 1"

[[endpoints]] #若本地有ipv6地址同样可以转发到别的ipv6地址
listen = "0.0.0.0:10000"
remote = "2001:4860:4860::8888:443"

端口映射(一)-- Realm

https://meloncloud.github.io/forward1/

Author

MelonCloud

Posted on

2024-11-08

Updated on

2024-11-10

Licensed under

Comments