trojan使用¶
在浏览youtube的时候发现一个视频:Trojan灭了V2ray?Trojan翻墙速度超乎想象?Trojan V2ray速度对比。里面比较了WebSocks+TLS实现的V2ray与Trojan,而当前仅使用了基于V2Mess协议的V2ray,并没有进一步配置WebSocks+TLS(太麻烦了),发现Trojan配置相对简单,果断入手
参考:
trojan简介¶
简单的说,SS/SSR等工具通过加密数据的方式来进行传输,而trojan-gfw/trojan使用的TroJan协议通过模拟正常的HTTPs连接的方式进行数据传输
完整流程¶
- 域名/证书配置
- 服务端配置(
Ubuntu 18.04) - 客户端配置(
Ubuntu 18.04 + Android) Service实现Docker实现
域名/证书配置¶
trojan需要配置域名和证书,可以申请免费的域名和证书
- 域名
- 证书
不过在国外的域名网站申请比较麻烦,我在阿里云上实现了域名申请、TLS证书申请和DNS解析(将域名和服务器IP绑定)
Note:对于阿里云SSL证书,使用其他类型即可;对于腾讯云SSL证书,使用Nginx类型即可
服务端配置¶
当前系统为Ubuntu 18.04,下载安装包 - trojan-1.14.0-linux-amd64.tar.xz。解压后文件列表如下:
├── config.json
├── CONTRIBUTORS.md
├── examples
│ ├── client.json-example
│ ├── forward.json-example
│ ├── nat.json-example
│ ├── server.json-example
│ └── trojan.service-example
├── LICENSE
├── README.md
├── trojan
其中trojan是已编译好的程序,查看其使用方式
# ./trojan --help
Welcome to trojan 1.14.0
usage: ./trojan [-htv] [-l LOG] [-k KEYLOG] [[-c] CONFIG]
options:
-c [ --config ] CONFIG (=config.json) specify config file
-h [ --help ] print help message
-k [ --keylog ] KEYLOG specify keylog file location (OpenSSL
>= 1.1.1)
-l [ --log ] LOG specify log file location
-t [ --test ] test config file
-v [ --version ] print version and build info
默认的config.json为服务端配置文件,修改其中的password/cert/key字段后,启动服务端
# ./trojan -c config.json
Welcome to trojan 1.14.0
[2019-12-31 19:14:16] [WARN] trojan service (server) started at 0.0.0.0:443
客户端配置¶
客户端分两种:桌面端和移动端
桌面端配置¶
当前系统为Ubuntu 18.04,同样先下载程序,解压后使用examples目录下的client.json-example配置文件(修改文件后缀名)。需要修改以下字段:
local_port:通常设置为1080,如果之前已配置其他代理软件,可设置其他端口以避免冲突remote_addr:域名password:输入在服务端设置的一个密码
完成设置后启动程序
$ ./trojan -c client.json
Welcome to trojan 1.14.0
[2019-12-31 19:19:46] [WARN] trojan service (client) started at 127.0.0.1:10801
移动端配置¶
下载Android apk - trojan-gfw/igniter
安装完成后打开应用,输入域名和密码即可登录
Service实现¶
经过上述服务端和客户端的配置后,已经能够实现VPN连接。为了进一步持久化运行,创建service文件进行配置
在/etc/systemd/system下新建trojan.service:
[Unit]
Description=Trojan
Documentation=https://trojan-gfw.github.io/trojan/
[Service]
ExecStart=/opt/trojan/trojan -c /opt/trojan/client.json -l /opt/trojan/trojan.log
Type=simple
KillMode=process
Restart=no
RestartSec=42s
[Install]
WantedBy=multi-user.target
启动服务并设置开机自启动
$ systemctl start trojan
$ systemctl enable trojan
Created symlink /etc/systemd/system/multi-user.target.wants/trojan.service → /etc/systemd/system/trojan.service.
$ systemctl status trojan
● trojan.service - Trojan
Loaded: loaded (/etc/systemd/system/trojan.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-12-31 19:57:29 CST; 4min 36s ago
Docs: https://trojan-gfw.github.io/trojan/
Main PID: 9018 (trojan)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/trojan.service
└─9018 /opt/trojan/trojan -c /opt/trojan/client.json -l /opt/trojan/trojan.log
12月 31 19:57:29 zj-ThinkPad-T470p systemd[1]: Started Trojan.
12月 31 19:57:29 zj-ThinkPad-T470p trojan[9018]: Welcome to trojan 1.14.0
如果之前已配置service文件,需要重新加载配置文件 - systemctl daemon-reload