Please help in configuring Xray for Keenetic router
Good afternoon and good mood, everyone!
I apologize in advance that the text may be inaccurate, because English and Chinese are not my native languages. I know English very superficially and use a translator.
I am asking for advice and help in configuring Xray on my Keenetic Ultra KN 1811 router. My knowledge of networking and Unix systems, as well as proxy server configuration is very limited, and I've only had a week to learn it.
The hardware and software details are as follows: Router: Keenetic Ultra KN 1811 Firmware: KeeneticOS 4.0.2 (Unix based system, similar to OpenWRT) Processor: Aarch64 cortex-a53 Xray Version: openwrt-xray_1.8.3-1_aarch64_cortex-a53
My Objectives: Establish protection, block bypass, and anonymity for specified VPS addresses. Implement traffic filtering (e.g., block ads, phishing) using a blocklist. Ensure DPI protection, block bypass, and anonymity for internal connections within the country when a remote server is not available. Proposed Setup Overview:
User device sends requests to the router.
- A device (Pc / Phone / Other) sends a user request to the router
- Xray on the router accepts requests using the Socks protocol.
- Xray classifies requests based on specified lists (e.g., VPS list, Inside list).
- Depending on the classification, appropriate strategies are applied.
- Consider the path of the Inside list
- Freedom protocol with "Quic" transport is selected.
- QuicSettings with header type "dtls" is used to disguise the traffic as a video stream.
- To improve security, transport protection with TLS settings is added.
- DNS queries are performed to the servers specified in the DNS section.
- The router establishes a connection to the received IP address.
- Xray processes the responses and forwards them to the router
- The router sends the responses back to the user device.
I hope I didn't confuse anything in the request path. As we can see, there is no additional external server in this bundle. Requests pass from the local network to the router, where they are processed, protected and sent to the Internet.
I tried to write a configuration for this path. This is the configuration on the router. This is the complete file that is there.
{
"log": {
"access": "/opt/var/log/xray/access.txt",
"error": "/opt/var/log/xray/error.txt",
"loglevel": "debug",
"dnsLog": true
},
"dns": {
"servers": [
"quic://dns.adguard-dns.com",
"quic://dns.futuredns.me",
"quic://doh.tiar.app"
],
"queryStrategy": "UseIP"
},
"inbounds": [
{
"tag": "socks",
"port": 1080,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true,
"allowTransparent": false
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls", "quic"]
}
}
],
"outbounds": [
{
"protocol": "freedom",
"streamSettings": {
"network": "quic",
"quicSettings": {
"key": "*",
"header": {
"type": "dtls"
}
},
"security": "tls",
"tlsSettings": {
"serverName": "www.youtube.com",
"minVersion": "1.3",
"fingerprint": "chrome",
"allowInsecure": false,
"certificates": [
{
"ocspStapling": 3600,
"oneTimeLoading": false,
"usage": "encipherment",
"certificateFile": "/opt/etc/tls/certs/tls-certificates.crt",
"keyFile": "/opt/etc/tls/private/tls-key.key"
}
]
},
"settings": {
"domainStrategy": "UseIP",
"fragment": {
"packets": "tlshello",
"length": 150,
"interval": 10
}
}
}
}
],
"stats": {}
}
I created a Socks connection in the router at 127.0.0.1:1080
Xray started. No errors.
Startup log: 2023/08/04 07:53:40 [Debug] app/log: Logger started 2023/08/04 07:53:40 [Info] app/dns: DNS: created UDP client initialized for quic://dns.adguard-dns.com:53 2023/08/04 07:53:40 [Info] app/dns: DNS: created UDP client initialized for quic://dns.futuredns.me:53 2023/08/04 07:53:40 [Info] app/dns: DNS: created UDP client initialized for quic://doh.tiar.app:53 2023/08/04 07:53:40 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:1080 2023/08/04 07:53:40 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1080 2023/08/04 07:53:40 [Info] transport/internet/udp: listening UDP on 127.0.0.1:1080 2023/08/04 07:53:40 [Warning] core: Xray 1.8.3 started
But DNS queries are still going through the ISP. Although the log shows that DNS is assigned. When I try to "opkg dns-override" on the router, the Internet stops working. When Xray is enabled in Wireshark, Quic protocols start to appear when connecting to Google servers. There are no other Quic protocols, classic TCP.
I honestly don't know what to do. I've done everything I can think of with my meager experience, but still nothing helps.
Additionally, I drew for you a diagram of what I'm talking about in English. I hope it will help you to understand the problem better.
I am asking for the community's help in solving this problem. I will be very grateful for all your recommendations and suggestions.
Thank you in advance for your time and support.
Let's assume that all requests sent by your device (including DNS) are sent to 127.0.0.1:1080.
Is that so?
You need to send the request for item 53 to "outboundTag": "dns-out" in the routing module. In the outbound module use "protocol": "dns" so that the DNS request will be processed in the Xray internal DNS module.
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"port": "53",
"outboundTag": "dns-out"
},
"outbounds": [
{
"protocol": "dns",
"tag": "dns-out"
}
If that's not what you're asking about, demand that you add some other information.
Let's assume that all requests sent by your device (including DNS) are sent to 127.0.0.1:1080.
Is that so?
You need to send the request for item 53 to "outboundTag": "dns-out" in the routing module. In the outbound module use "protocol": "dns" so that the DNS request will be processed in the Xray internal DNS module.
"routing": { "domainStrategy": "IPIfNonMatch", "rules": [ { "type": "field", "port": "53", "outboundTag": "dns-out" },"outbounds": [ { "protocol": "dns", "tag": "dns-out" }If that's not what you're asking about, demand that you add some other information.
Thank you for trying to help! Maybe some additional information is needed?
Here's what I've had time to try and the results.
-
I added forwarding of all ports (tcp/udp (all ports) and icmp) in the router using the following rules: 127.0.0.1/32 to Xray Proxy server (127.0.0.1:1080). Result: The problems persist. Nothing has changed.
-
Added port forwarding 53 TCP/UDP to 1080. Result: The problems persisted. Nothing changed.
-
Disabled the default DNS from IPS. Result: The problems persisted. Nothing changed.
-
Used opkg dns-override. Result: The problems persisted. Nothing changed.
-
I used all of this in combination with the config from the hat and the updated one recommended. Result: The problems persisted. Nothing changed.
The updated config was rewritten as follows:
{
"log": {
"access": "/opt/var/log/xray/access.txt",
"error": "/opt/var/log/xray/error.txt",
"loglevel": "debug",
"dnsLog": true
},
"dns": {
"servers": [
"quic://dns.adguard-dns.com",
"quic://dns.futuredns.me",
"quic://doh.tiar.app"
],
"queryStrategy": "UseIP"
},
"inbounds": [
{
"tag": "socks",
"port": 1080,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true,
"allowTransparent": false
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls", "quic"]
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {
"domainStrategy": "UseIP"
},
"streamSettings": {
"network": "quic",
"security": "tls",
"quicSettings": {
"key": "10111940qWe",
"header": {
"type": "srtp"
}
},
"tlsSettings": {
"minVersion": "1.3",
"fingerprint": "chrome",
"allowInsecure": false,
"certificates": [
{
"certificateFile": "/opt/etc/tls/certs/tls-certificates.crt",
"keyFile": "/opt/etc/tls/private/tls-key.key"
}
]
}
}
},
{
"protocol": "dns",
"tag": "dns-out"
}
],
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"port": "53",
"outboundTag": "dns-out"
}
]
},
"stats": {}
}
Sorry, I just thought about it and I gave you the wrong approach.
You gave the full request only to port 1080, using the
{
"type": "field",
"port": "53",
"outboundTag": "dns-out"
}
This rule works.
Can you hijack all UDP port 53 traffic in your front-end transparent proxy program, assuming it is given to the local port 10853. (An example would be using tun2socks mode. I'm not sure how your front-end handles the job of hijacking traffic)
Let's now assume that you have taken the UDP port 53 traffic and sent it to the local port 10853, and can refer to this configuration.
https://github.com/chika0801/Xray-examples/blob/main/v2rayNG_custom.json
He's using Xray's free gate inbound feature to receive port 10853.
{
"listen": "127.0.0.1",
"port": 10853,
"protocol": "dokodemo-door",
"settings": {
"address": "1.1.1.1",
"port": 53,
"network": "udp"
},
"tag": "dns-in"
}
With this routing rule
"rules": [
{
"type": "field",
"inboundTag": [
"dns-in"
],
"outboundTag": "dns-out"
},
Carry out the outbound counterpart of this rule
{
"protocol": "dns",
"settings": {
"nonIPQuery": "drop"
},
"proxySettings": {
"tag": "proxy"
},
"tag": "dns-out"
}
Then go to Xray's internal DNS module.
If you have this setup, for example, you can set its DNS address, you set it to 127.0.0.1.
So that in the Xray configuration it would look like this
{
"listen": "127.0.0.1",
"port": 53,
"protocol": "dokodemo-door",
"settings": {
"address": "1.1.1.1",
"port": 53,
"network": "udp"
},
"tag": "dns-in"
}
"rules": [
{
"type": "field",
"inboundTag": [
"dns-in"
],
"outboundTag": "dns-out"
},
{
"protocol": "dns",
"settings": {
"nonIPQuery": "skip"
},
"tag": "dns-out"
}