端口配置
端口是 SagerNet代理连接到网络设备的关键部分,以下是一个基本的配置格式:
# 设置默认端口 ip route all-wp -p 88 # 设置备用端口(可选) ip route all-wp -p 881 88
- 默认端口:通常设置为
88,适用于外网。 - 备用端口:
881是外网的备用端口,88是内网备用端口。
IP地址配置
设置 SagerNet代理的IP地址范围:
ip linkset 192.168.1./24
- 地址:
168.1.是一个虚拟地址,方便管理,建议将实际服务器地址替换为实际IP地址。 - 子网掩码:
/24表示一个IP地址包含24位,允许254个子网。
代理配置文件
设置代理配置文件的路径:
echo "sagernet.conf" > /etc/sagernet.conf
创建或修改 sagernet.conf 文件:
echo "version: AP 1..\nversion rev: 0\nversion date: 223-1-1\nversion author: SagerNet\nversion author email: info@sagernet.com\nversion author website: https://sagernet.net\nversion author GitHub: https://github.com/sagernet" > /etc/sagernet.conf
设置代理的配置:
echo "default host: 'localhost'\ndefault port: 88\ndefault port type: external\ndefault port id: 88\ndefault root: 'admin'\ndefault user: 'system'\ndefault password: 'sagernet'\ndefault scope: read, write" > /etc/sagernet.conf
防火墙配置
设置防火墙来管理代理的访问:
iptables
-
IP防火墙:
iptables -A INPUT -p 8.8.8./32 -j algebra=ip -j label=88 -o output -j algebra=ip -j action=write iptables -A INPUT -p 8.8.8./32 -j algebra=ip -j label=881 -o output -j algebra=ip -j action=write
-
端口防火墙:
iptables -A INPUT -p 88 -j algebra=port -j label=external -o output -j algebra=port -j action=write iptables -A INPUT -p 881 -j algebra=port -j label=internal -o output -j algebra=port -j action=write
访问控制配置
设置访问控制规则:
sudo useradd -m "管理员" -p /path/to/sagernet.conf -u SagerNet sudo useradd -m "管理员" -p /path/to/sagernet.conf -u SagerNet
sudo add-arg access 8
- 访问权限:
8表示读写操作。 - 访问控制:设置访问控制规则,例如读写、读取、权限等。
防火墙设置
设置防火墙来限制代理的访问:
sudo iptables -A -A INPUT -p 8.8.8./32 -j algebra=ip -j label=88 -o output -j algebra=ip -j action=write
日志配置
设置日志级别:
sudo logcat -u SagerNet
备份与恢复
- 备份:定期备份代理的状态。
- 恢复:在需要时进行恢复操作。


