Trojan Rust

Entry Node

Configuring the relay chain entry node

The entry node (A) accepts client connections and builds tunnels through the relay chain to the exit server.

Running

trojan entry -c entry.toml

Chains and Rules

The entry node configuration separates chains (relay paths) from rules (port-to-chain mappings).

Chain

A chain defines an ordered list of relay nodes. It does not include the final destination.

[chains.jp]
nodes = [
  { addr = "relay-hk.example.com:443", password = "hk-secret", transport = "tls", sni = "crates.io" },
]

[chains.us]
nodes = [
  { addr = "relay-hk.example.com:443", password = "hk-secret", transport = "tls", sni = "crates.io" },
  { addr = "relay-la.example.com:8080", password = "la-secret", transport = "plain" },
]

[chains.direct]
nodes = []          # No relay, direct connection to destination

Node Options

OptionTypeDescription
addrstringRelay node address (host:port)
passwordstringRelay authentication password
transportstring"tls" or "plain"
snistringTLS SNI hostname (optional, for TLS transport)

Rule

A rule binds a listen port to a chain and a destination:

[[rules]]
name = "japan"
listen = "127.0.0.1:1080"
chain = "jp"
dest = "trojan-jp.example.com:443"

[[rules]]
name = "united-states"
listen = "127.0.0.1:1081"
chain = "us"
dest = "trojan-us.example.com:443"

Rule Options

OptionTypeDescription
namestringRule name (for logging)
listenstringLocal listen address
chainstringChain name to use
deststringExit server address (host:port)

Sharing Chains

Multiple rules can share the same chain with different destinations:

[[rules]]
name = "japan-via-hk"
listen = "127.0.0.1:1080"
chain = "asia"
dest = "trojan-jp.example.com:443"

[[rules]]
name = "korea-via-hk"
listen = "127.0.0.1:1083"
chain = "asia"
dest = "trojan-kr.example.com:443"

Complete Example

# Two chains: one via HK relay, one direct
[chains.via-hk]
nodes = [
  { addr = "relay-hk.example.com:443", password = "hk-relay-pw", transport = "tls", sni = "crates.io" },
]

[chains.direct]
nodes = []

# Japan server via HK relay
[[rules]]
name = "japan"
listen = "127.0.0.1:1080"
chain = "via-hk"
dest = "trojan-jp.example.com:443"

# US server direct
[[rules]]
name = "us-direct"
listen = "127.0.0.1:1081"
chain = "direct"
dest = "trojan-us.example.com:443"

On this page