55
66## How to use it?
77
8- ### 1. Setup ` xray ` inbound
8+ ### 1. Setup ` xray ` config
9+ 1 . Setup ` xray ` inbound
10+
11+ ` xray ` should use a paticular ` tproxy ` inbound to receive traffice routed from within the container.
912
1013``` jsonc
1114{
1215 " inbounds" : [
16+ // tproxy rule
1317 {
1418 " port" : 12345 , // this port must match `XRAY_INBOUND_PORT` env variable
1519 " protocol" : " dokodemo-door" ,
2327 }
2428 }
2529 },
26- { // this inbound is optional but normally useful
27- " tag" : " socks" ,
28- " port" : 7070 ,
29- " protocol" : " mixed" ,
30- " sniffing" : {
31- " enabled" : true ,
32- " destOverride" : [
33- " http" ,
34- " tls"
35- ],
36- " routeOnly" : false
37- },
30+ // other inbounds ...
31+ ]
32+ }
33+ ```
34+
35+ 2 . Setup ` xray ` outbound
36+
37+ For the ** outbound** settings, the [ DNS redirection] ( #dns-redirection ) is required in case of DNS leak.
38+
39+ Here is an example of ** DNS outbound** in xray config:
40+
41+ ``` json
42+ {
43+ "outbounds" : [
44+ // your outbound to remote server
45+ {
46+ "tag" : " proxy" ,
47+ // ...
48+ },
49+
50+ // DNS outbound via proxy
51+ {
52+ "tag" : " out-dns" ,
53+ "protocol" : " dns" ,
3854 "settings" : {
39- " auth" : " noauth" ,
40- " udp" : true ,
41- " allowTransparent" : false
55+ "address" : " 8.8.8.8"
56+ },
57+ "proxySettings" : {
58+ "tag" : " proxy"
4259 }
60+ },
61+
62+ {
63+ "tag" : " direct" ,
64+ "protocol" : " freedom"
65+ },
66+ {
67+ "tag" : " block" ,
68+ "protocol" : " blackhole"
4369 }
4470 ]
4571}
4672```
4773
48- For the ** outbound** settings, check the [ DNS redirection] ( #dns-redirection ) section.
74+ 3 . Setup ` xray ` routing
75+
76+ This is routing rules is for [ DNS redirection] ( #dns-redirection ) in case of DNS leak.
77+
78+ ``` jsonc
79+ {
80+ " routing" : {
81+ " domainStrategy" : " AsIs" ,
82+ " rules" : [
83+ // DNS redirection
84+ {
85+ " type" : " field" ,
86+ " port" : 53 ,
87+ " outboundTag" : " out-dns"
88+ },
89+ // other rules ...
90+ ]
91+ }
92+ }
93+ ```
4994
5095### 2. Run ` xray-tproxy ` with docker-compose
5196
97+ After you've setup your config, you can run ` xray-tproxy ` with docker-compose.
98+
5299Copy and modify the following ` docker-compose.yml ` file:
53100
54101``` yaml
@@ -67,9 +114,14 @@ services:
67114 XRAY_INBOUND_PORT : " 12345" # must match inbound port to xray
68115 LOCAL_DNS : " 114.114.114.114"
69116 RESERVED_IPS : " 0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 224.0.0.0/4 240.0.0.0/4"
117+ # Using config folder in this case
70118 volumes :
71- - ./xray :/etc/xray/config
119+ - ./config :/etc/xray/config
72120 command : ["xray", "run", "-confdir", "/etc/xray/config"]
121+ # You can also use `config.json` file:
122+ # volumes:
123+ # - ./config.json:/etc/xray/config.json
124+ # command: ["xray", "run", "-c", "/etc/xray/config.json"]
73125
74126networks :
75127 tproxyvlan :
@@ -84,23 +136,22 @@ networks:
84136 gateway : " 192.168.2.1"
85137` ` `
86138
87- and for the first time,then run:
139+ and for the first time, run:
88140
89141` ` ` bash
90142docker-compose up
91143```
92144
93- You can see the logs. If everything works well, press ` Ctrl-C ` to close the log. The service still runs in the background.
145+ You can see the logs. If everything goes well, press ` Ctrl-C ` to close the log. The service still runs in the background.
94146
95147You can also use ` docker-compose logs -f ` to see the logs in real time.
96148
97- If everything goes well , you can run command below without logs:
149+ If everything works , you can run command below without logs:
98150
99151``` bash
100152docker-comopse up -d
101153```
102154
103-
104155### (Optional) Run ` ash ` to debug
105156
106157You can run ` docker exec -it tproxy ash ` to run ` ash ` in the container.
@@ -133,7 +184,7 @@ All the environment variables that you can set in `docker-compose.yaml` file:
133184
134185> Note: Set these environment variables will override the default ones.
135186
136- ## Important notes
187+ ## Other topics
137188
138189### DNS redirection
139190
@@ -142,35 +193,3 @@ All the environment variables that you can set in `docker-compose.yaml` file:
142193* In this way, set your devices' DNS server to ` 114.114.114.114 ` or ` 8.8.8.8 ` has the same result.
143194* However, don't use your LAN DNS server, e.g. ` 192.168.1.1 ` . The DNS traffic doesn't route to ` xray-tproxy ` , and thus is not protected.
144195
145- Here is an example of ** DNS outbound** in xray config:
146-
147- ``` json
148- {
149- "outbounds" : [
150- {
151- // your outbound to remote server
152- "tag" : " proxy" ,
153- // ...
154- },
155- {
156- // DNS outbound via proxy
157- "tag" : " out-dns" ,
158- "protocol" : " dns" ,
159- "settings" : {
160- "address" : " 8.8.8.8"
161- },
162- "proxySettings" : {
163- "tag" : " proxy"
164- }
165- },
166- {
167- "tag" : " direct" ,
168- "protocol" : " freedom"
169- },
170- {
171- "tag" : " block" ,
172- "protocol" : " blackhole"
173- }
174- ]
175- }
176- ```
0 commit comments