步骤 1:安装Trojan节点
-
下载Trojan源码
- 访问Trojan的官方GitHub仓库:https://github.com/RustCrypto/Trojan
- 克隆仓库:
git clone https://github.com/RustCrypto/Trojan.git
-
进入项目目录
cd /path/to/Trojan
-
安装Trojan依赖
- 安装Rust和其他依赖:
cargo install --features all - 安装系统依赖(如
liburing):- Debian/Ubuntu:
sudo apt-get install liburing-dev - Fedora:
sudo dnf install liburing-dev-Arch Linux:sudo pacman -S liburing-dev
- Debian/Ubuntu:
- 安装Rust和其他依赖:
-
编译Trojan
cargo build --release
-
安装Trojan节点程序
sudo cargo install --bin
步骤 2:配置Trojan节点
-
创建配置文件
-
打开文本编辑器,新建一个文件,例如
trojan.conf。 -
[Node] Address = 127...1:1234 Listen = true # 随机化端口 Port = random # 允许连接外部节点 Enabled = true # 禁止外部连接 External = false # 隐蔽性设置 Invert = false # 随机化连接时间 Randomize = 100 # 连接超时(秒) ConnectTimeout = 60 # 节点ID NodeID = "my-trojan-node"
- Address:设置绑定地址,建议使用本地IP。
- Port:可以设置随机化端口,提高安全性。
- Enabled:启用节点。
- External:决定是否允许外部连接。
- NodeID:唯一的节点ID。
-
-
生成API密钥
- 运行命令生成API密钥:
./trojan-node genkeypair
- 这会生成两个密钥文件:
api-in.pem和api-out.pem。
- 运行命令生成API密钥:
-
配置防火墙
- 根据你的网络环境,确保防火墙允许端口1234的TCP流量:
- Debian/Ubuntu:
sudo ufw allow 1234/tcp - Fedora:
sudo firewallctl --add-service=trojan/tcp - Arch Linux:
sudo iptables -A INPUT -p tcp --dport 1234 -j ACCEPT
- Debian/Ubuntu:
- 根据你的网络环境,确保防火墙允许端口1234的TCP流量:
步骤 3:运行Trojan节点
-
启动节点
- 使用配置文件启动:
sudo ./trojan-node -c /path/to/trojan.conf
- 或者指定API密钥:
sudo ./trojan-node -c /path/to/trojan.conf --api-in-file /path/to/api-in.pem --api-out-file /path/to/api-out.pem
- 使用配置文件启动:
-
设置开机启动
-
创建启动脚本(例如
trojan.service):[Unit] Description=Trojan Node [Service] ExecStart=/path/to/trojan-node -c /path/to/trojan.conf Restart=always [Install] WantedBy=multi-user.target
-
保存并复制到服务目录:
sudo cp /path/to/trojan.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable trojan.service
-
步骤 4:验证配置
-
查看日志
journalctl -u trojan.service -b查看启动日志。
-
测试连接
- 使用另一设备(在同一网络内)连接到你的Trojan节点:
nc -zv 127...1 1234
- 检查是否能成功连接。
- 使用另一设备(在同一网络内)连接到你的Trojan节点:
-
查看节点列表
- 使用
trojan-node list查看已连接的节点。
- 使用
注意事项
- 安全性:确保API密钥和密码强安全,避免泄露。
- 网络环境:根据网络环境调整配置,如防火墙设置。
- 维护:定期检查日志,处理潜在问题。
通过以上步骤,你可以配置并运行一个安全的Trojan节点,用于点对点网络的有效连接。









