@@ -157,7 +157,176 @@ All modes support these additional options:
157157
158158## Configuration
159159
160- ### Default Payload Template
160+ Tunn supports two configuration approaches: traditional CLI flags and Xray-like configuration files for advanced users.
161+
162+ ### Configuration Files (Xray-like)
163+
164+ Tunn supports JSON and YAML configuration files for managing complex tunnel configurations with multiple profiles, routing rules, and environment variable substitution.
165+
166+ #### Configuration Structure
167+
168+ ``` json
169+ {
170+ "log" : {
171+ "level" : " info" ,
172+ "access" : " /var/log/tunn/access.log" ,
173+ "error" : " /var/log/tunn/error.log"
174+ },
175+ "inbounds" : [... ],
176+ "outbounds" : [... ],
177+ "routing" : {... },
178+ "dns" : {... },
179+ "profiles" : [... ]
180+ }
181+ ```
182+
183+ #### Profiles Section
184+
185+ The ` profiles ` section is the main configuration area for tunnel definitions:
186+
187+ ``` json
188+ {
189+ "profiles" : [
190+ {
191+ "name" : " default" ,
192+ "mode" : " proxy" ,
193+ "proxyHost" : " proxy.example.com" ,
194+ "proxyPort" : " 80" ,
195+ "targetHost" : " target.example.com" ,
196+ "targetPort" : " 22" ,
197+ "frontDomain" : " google.com" ,
198+ "ssh" : {
199+ "username" : " user" ,
200+ "password" : " password" ,
201+ "port" : " 22"
202+ },
203+ "localPort" : 1080 ,
204+ "proxyType" : " socks5" ,
205+ "payload" : " GET / HTTP/1.1\\ r\\ nHost: $FRONT_DOMAIN\\ r\\ nUpgrade: websocket\\ r\\ n\\ r\\ n" ,
206+ "timeout" : 30
207+ }
208+ ]
209+ }
210+ ```
211+
212+ #### Configuration Management Commands
213+
214+ ``` bash
215+ # Generate sample configuration
216+ tunn config generate --output tunn-config.json --format json
217+ tunn config generate --output tunn-config.yaml --format yaml
218+
219+ # Validate configuration
220+ tunn config validate --config tunn-config.json
221+
222+ # List available profiles
223+ tunn config list --config tunn-config.json
224+
225+ # Use configuration with profiles
226+ tunn --config tunn-config.json --profile default proxy
227+ tunn --config tunn-config.json --profile sni-mode sni
228+
229+ # Override configuration with CLI flags
230+ tunn --config tunn-config.json --profile default --proxy-type http proxy
231+ ```
232+
233+ #### Environment Variables in Configuration
234+
235+ Configuration files support environment variable substitution using the ` $VARIABLE ` syntax:
236+
237+ ``` json
238+ {
239+ "profiles" : [
240+ {
241+ "name" : " production" ,
242+ "targetHost" : " $TARGET_HOST" ,
243+ "ssh" : {
244+ "username" : " $SSH_USERNAME" ,
245+ "password" : " $SSH_PASSWORD"
246+ }
247+ }
248+ ]
249+ }
250+ ```
251+
252+ Set environment variables before running:
253+
254+ ``` bash
255+ export TARGET_HOST=" prod.example.com"
256+ export SSH_USERNAME=" admin"
257+ export SSH_PASSWORD=" secret"
258+
259+ tunn --config config.json --profile production proxy
260+ ```
261+
262+ #### Advanced Configuration Features
263+
264+ ** Routing Rules:**
265+
266+ ``` json
267+ {
268+ "routing" : {
269+ "domainStrategy" : " IPIfNonMatch" ,
270+ "rules" : [
271+ {
272+ "type" : " field" ,
273+ "domain" : [" geosite:cn" ],
274+ "outboundTag" : " freedom"
275+ },
276+ {
277+ "type" : " field" ,
278+ "ip" : [" geoip:private" ],
279+ "outboundTag" : " freedom"
280+ }
281+ ]
282+ }
283+ }
284+ ```
285+
286+ ** Inbound/Outbound Configuration:**
287+
288+ ``` json
289+ {
290+ "inbounds" : [
291+ {
292+ "tag" : " socks-in" ,
293+ "port" : 1080 ,
294+ "listen" : " 127.0.0.1" ,
295+ "protocol" : " socks"
296+ }
297+ ],
298+ "outbounds" : [
299+ {
300+ "tag" : " tunnel-out" ,
301+ "protocol" : " tunnel" ,
302+ "streamSettings" : {
303+ "network" : " ws" ,
304+ "security" : " tls"
305+ }
306+ }
307+ ]
308+ }
309+ ```
310+
311+ ** DNS Configuration:**
312+
313+ ``` json
314+ {
315+ "dns" : {
316+ "hosts" : {
317+ "example.com" : " 127.0.0.1"
318+ },
319+ "servers" : [
320+ " 8.8.8.8" ,
321+ " 1.1.1.1"
322+ ]
323+ }
324+ }
325+ ```
326+
327+ ### CLI Configuration (Traditional)
328+
329+ #### Default Payload Template
161330
162331```
163332GET / HTTP/1.1[crlf]Host: [host][crlf]Upgrade: websocket[crlf][crlf]
@@ -167,7 +336,7 @@ Placeholders:
167336- ` [host] ` : Replaced with target host or front domain
168337- ` [crlf] ` : Replaced with ` \r\n `
169338
170- ### Custom Payloads
339+ #### Custom Payloads
171340
172341You can specify custom HTTP payloads for different environments:
173342
@@ -432,6 +601,28 @@ The release process automatically:
432601
433602## Troubleshooting
434603
604+ ### Configuration File Issues
605+
606+ ** Invalid Configuration** : Use ` tunn config validate ` to check for syntax errors
607+
608+ ** Missing Required Fields** : Ensure all required fields are present in profiles
609+
610+ ** Environment Variables** : Make sure environment variables are set before running
611+
612+ ** File Permissions** : Ensure the configuration file is readable
613+
614+ ** Debug Mode** : Use verbose mode to see configuration loading details:
615+
616+ ``` bash
617+ tunn --config config.json --profile myprofile --verbose proxy
618+ ```
619+
620+ This will show:
621+ - Configuration file loading status
622+ - Profile selection
623+ - Environment variable substitution
624+ - Validation results
625+
435626### Common Issues
436627
437628** Connection Timeout** :
0 commit comments