Skip to content

Optimized Config for OpenWrt (Delay 25 & Lower CPU) + Auto-install Script #22

Description

@pasehvar

سلام، من این کانفیگ رو برای OpenWrt بهینه‌سازی کردم (تغییر دیلی به ۲۵ و کاهش نویزها برای مصرف کمتر CPU) و یک اسکریپت نصب خودکار با Bash هم براش نوشتم تا کاربران بتونن با یک کلیک سرویس رو راه‌اندازی کنن. لطفاً در صورت صلاحدید به پروژه اضافه کنید.

این اسکریپت پکیج xray-core رو نصب می‌کنه، کانفیگ رو می‌سازه و سرویس init.d رو برای اجرای خودکار فعال می‌کنه:

#!/bin/sh

echo "🚀 Starting OpenWrt Xray-Serverless Setup..."

# 1. Update and install Xray
echo "📦 Installing xray-core..."
apk update
apk add xray-core

# 2. Create directory and config file
echo "⚙️ Creating configuration file..."
mkdir -p /etc/xray

cat << 'EOF' > /etc/xray/serverless.json
{
    "log": {
        "loglevel": "warning",
        "dnsLog": false,
        "access": "none"
    },
    "policy": {
        "levels": {
            "0": { "uplinkOnly": 0, "downlinkOnly": 0 },
            "1": { "uplinkOnly": 0, "downlinkOnly": 0, "connIdle": 12 }
        }
    },
    "dns": {
        "hosts": {
            "cloudflare-dns.com": "challenges.cloudflare.com",
            "challenges.cloudflare.com": "104.16.249.249"
        },
        "servers": [
            {
                "address": "fakedns",
                "domains": [
                    "domain:ir", "geosite:private", "geosite:category-ir",
                    "geosite:xai", "geosite:openai", "geosite:google-deepmind",
                    "geosite:anthropic", "geosite:github", "geosite:microsoft",
                    "geosite:golang", "geosite:python", "geosite:rust",
                    "full:challenges.cloudflare.com"
                ]
            },
            {
                "tag": "no-filter-dns",
                "address": "[https://cloudflare-dns.com/dns-query](https://cloudflare-dns.com/dns-query)",
                "timeoutMs": 12000,
                "finalQuery": true
            },
            {
                "address": "localhost",
                "domains": [
                    "domain:ir", "geosite:private", "geosite:category-ir",
                    "geosite:xai", "geosite:openai", "geosite:google-deepmind",
                    "geosite:anthropic", "geosite:github", "geosite:microsoft",
                    "geosite:golang", "geosite:python", "geosite:rust",
                    "full:challenges.cloudflare.com"
                ],
                "finalQuery": true
            }
        ],
        "queryStrategy": "UseSystem",
        "useSystemHosts": true,
        "serveStale": true
    },
    "inbounds": [
        {
            "tag": "mixed-in",
            "port": 10808,
            "protocol": "mixed",
            "sniffing": {
                "enabled": true,
                "destOverride": ["fakedns", "tls", "http", "quic"],
                "routeOnly": false
            },
            "settings": { "udp": true, "ip": "127.0.0.1" },
            "streamSettings": { "sockopt": { "tcpKeepAliveInterval": 1, "tcpKeepAliveIdle": 11 } }
        }
    ],
    "outbounds": [
        { "tag": "block", "protocol": "block" },
        {
            "tag": "tcp-direct", "protocol": "direct",
            "streamSettings": { "sockopt": { "domainStrategy": "ForceIP", "happyEyeballs": { "tryDelayMs": 300, "prioritizeIPv6": true, "interleave": 2, "maxConcurrentTry": 20 } } }
        },
        { "tag": "udp-direct", "protocol": "direct", "settings": { "targetStrategy": "ForceIPv6v4" } },
        { "tag": "dns-out", "protocol": "dns", "settings": { "userLevel": 1 } },
        {
            "tag": "tcp-fragment", "protocol": "direct",
            "streamSettings": {
                "finalmask": {
                    "tcp": [ { "type": "fragment", "settings": { "packets": "1-1", "length": "1", "delay": "25", "maxSplit": "163" } } ]
                },
                "sockopt": { "domainStrategy": "ForceIP", "happyEyeballs": { "tryDelayMs": 300, "prioritizeIPv6": true, "interleave": 2, "maxConcurrentTry": 20 } }
            }
        },
        {
            "tag": "tcp-fragment-tls", "protocol": "direct",
            "streamSettings": {
                "finalmask": {
                    "tcp": [
                        { "type": "fragment", "settings": { "packets": "1-1", "length": "1", "delay": "25", "maxSplit": "163" } },
                        { "type": "fragment", "settings": { "packets": "tlshello", "length": "124", "delay": "0", "maxSplit": "0" } }
                    ]
                },
                "sockopt": { "domainStrategy": "ForceIP", "happyEyeballs": { "tryDelayMs": 300, "prioritizeIPv6": true, "interleave": 2, "maxConcurrentTry": 20 } }
            }
        },
        {
            "tag": "udp-noises", "protocol": "direct", "settings": { "targetStrategy": "ForceIPv6v4" },
            "streamSettings": {
                "finalmask": {
                    "udp": [
                        {
                            "type": "noise",
                            "settings": {
                                "reset": "28",
                                "noise": [
                                    { "rand": "1200-1230", "delay": "10" },
                                    { "rand": "1200-1230", "delay": "10" },
                                    { "rand": "1200-1230", "delay": "10" },
                                    { "rand": "1200-1230", "delay": "10" }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    ],
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            { "outboundTag": "tcp-fragment", "inboundTag": ["no-filter-dns"] },
            { "outboundTag": "dns-out", "port": 53 },
            { "outboundTag": "tcp-direct", "network": "tcp", "domain": ["domain:ir", "geosite:private", "geosite:category-ir", "geosite:xai", "geosite:openai", "geosite:google-deepmind", "geosite:anthropic", "geosite:github", "geosite:microsoft", "geosite:golang", "geosite:python", "geosite:rust"] },
            { "outboundTag": "udp-direct", "network": "udp", "domain": ["domain:ir", "geosite:private", "geosite:category-ir", "geosite:xai", "geosite:openai", "geosite:google-deepmind", "geosite:anthropic", "geosite:github", "geosite:microsoft", "geosite:golang", "geosite:python", "geosite:rust"] },
            { "outboundTag": "block", "ip": ["10.10.34.0/24", "2001:4188:2:600::/64"] },
            { "outboundTag": "tcp-direct", "network": "tcp", "ip": ["geoip:private", "geoip:ir"] },
            { "outboundTag": "udp-direct", "network": "udp", "ip": ["geoip:private", "geoip:ir"] },
            { "outboundTag": "udp-noises", "network": "udp", "protocol": ["quic"], "ip": ["0.0.0.0/0", "::/0"] },
            { "outboundTag": "udp-noises", "network": "udp", "port": "443", "ip": ["0.0.0.0/0", "::/0"] },
            { "outboundTag": "udp-direct", "network": "udp", "ip": ["0.0.0.0/0", "::/0"] },
            { "outboundTag": "tcp-fragment", "network": "tcp", "protocol": ["tls"], "ip": ["0.0.0.0/0", "::/0"] },
            { "outboundTag": "tcp-fragment", "network": "tcp", "port": "443", "ip": ["0.0.0.0/0", "::/0"] },
            { "outboundTag": "tcp-fragment", "network": "tcp", "ip": ["0.0.0.0/0", "::/0"] },
            { "outboundTag": "block", "port": "0-65535" }
        ]
    }
}
EOF

# 3. Create OpenWrt init.d service
echo "🔧 Creating init.d service..."
cat << 'EOF' > /etc/init.d/xrayserverless
#!/bin/sh /etc/rc.common

START=99
STOP=10

USE_PROCD=1
PROG=/usr/bin/xray

start_service() {
    procd_open_instance
    procd_set_param command "$PROG" run -c /etc/xray/serverless.json
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_set_param respawn
    procd_close_instance
}
EOF

chmod +x /etc/init.d/xrayserverless

# 4. Enable and start service
echo "▶️ Enabling and starting service..."
/etc/init.d/xrayserverless enable
/etc/init.d/xrayserverless start

echo "✅ All Done! Xray is running on port 10808."
echo "You can now route Passwall to 127.0.0.1:10808 using SOCKS."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions