X-UI面板进阶教程,自定义DNS分流/多IP出口

X-UI面板进阶教程,自定义DNS分流/多IP出口

sockat
2023-10-17 / 8 评论 / 1,045 阅读 / 正在检测是否收录...

  在前文中我们介绍了XUI面板搭建基础教程,但实际使用过程中会用到更多样化的配置,比如给节点配置DNS流媒体解锁、根据不同情况分流至相应的服务出口、多IP出口地址,XUI面板采用的Xray核心框架,也就对应支持xray的自定义功能,本文对其详细配置进行说明。

lnsmvoc7.png

认识Xray三兄弟

 1、进入到xui面板设置中,找到“xray 相关设置”,在这里是xray配置模板,修改其中的部分参数就能达到所需要的各种效果;

lnsnd21k.png

 2、Xray配置主要有入站(inbounds)、出站(outbounds)、路由(routing)三大项,其中入站通过xui面板API获取,出站则表示流量怎么流出,路由则是把入口跟出口串联起来;

DNS分流

 1、常用情况下会用到DNS来分流解锁一些流媒体网站,进行域名分流在 inbounds 段新增代码开启流量识别功能,如下;

  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 62789,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "sniffing": {
      "enabled": true,
      "destOverride": ["http", "tls"]
      },
      "tag": "api"
    }
  ]

 2、在 outbounds 段内的首项配置中添加 "domainStrategy": "UseIP" 以使用内置的DNS功能,如下;

  "outbounds": [
    {
    "protocol": "freedom",
    "settings": {"domainStrategy": "UseIP"}
    },
    {
      "protocol": "blackhole",
      "settings": {},
      "tag": "blocked"
    }
  ]

 3、在配置文件末尾最后的括号内添加要走DNS解锁的分流网站域名规则等;

  "dns": {
    "servers": [
      "8.8.8.8",
      {
        "address": "x.x.x.x", //DNS提供的解锁IP
        "port": 53,
        "domains": ["geosite:netflix"]  //要解锁的网站或geo文件名
      }
    ]
  }

 4、完全版配置如下,可直接复制粘贴替换掉配置模板内容,注意修改DNS信息;

{
  "api": {
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService"
    ],
    "tag": "api"
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 62789,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "sniffing": {
      "enabled": true, 
      "destOverride": ["http", "tls"]
      },
      "tag": "api"
    }
  ],
  "outbounds": [
    {
    "protocol": "freedom",
    "settings": {"domainStrategy": "UseIP"}
    },
    {
      "protocol": "blackhole",
      "settings": {},
      "tag": "blocked"
    }
  ],
  "policy": {
    "system": {
      "statsInboundDownlink": true,
      "statsInboundUplink": true
    }
  },
  "routing": {
    "rules": [
      {
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api",
        "type": "field"
      },
      {
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "blocked",
        "type": "field"
      },
      {
        "outboundTag": "blocked",
        "protocol": [
          "bittorrent"
        ],
        "type": "field"
      }
    ]
  },
  "stats": {},
  "dns": {
    "servers": [
      "8.8.8.8",
      {
        "address": "x.x.x.x", 
        "port": 53,
        "domains": ["geosite:netflix","geosite:disney"]
      }
    ]
  }
}

出口分流配置

 设置不同的出站方式,然后通过路由串联tag或匹配规则的形式可以达到不同入站节点走不同出口、又或是分流不同域名流量,其中XUI面板生成的默认入站TAG格式为: inbound-端口号 ,对应入站列表内的每条节点;
   示例1 :多个节点对应不同出口IP地址

{
  "api": {
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService"
    ],
    "tag": "api"
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 62789,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "tag": "api"
    }
  ],

  "outbounds": [
    {
      "tag": "ip1",
      "sendThrough": "1.1.1.1",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "ip2",
      "sendThrough": "1.1.1.2",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "ip3",
      "sendThrough": "1.1.1.3",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "protocol": "freedom",
      "settings": {}
    },
    {
      "protocol": "blackhole",
      "settings": {},
      "tag": "blocked"
    }
  ],
  "policy": {
    "system": {
      "statsInboundDownlink": true,
      "statsInboundUplink": true
    }
  },

  "routing": {
    "rules": [
      {
        "inboundTag": [
          "inbound-12881"
        ],
        "outboundTag": "ip1",
        "type": "field"
      },
      {
        "inboundTag": [
          "inbound-12882"
        ],
        "outboundTag": "ip2",
        "type": "field"
      },
      {
        "inboundTag": [
          "inbound-12883"
        ],
        "outboundTag": "ip3",
        "type": "field"
      },
      {
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api",
        "type": "field"
      },
      {
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "blocked",
        "type": "field"
      },
      {
        "outboundTag": "blocked",
        "protocol": [
          "bittorrent"
        ],
        "type": "field"
      }
    ]
  },
  "stats": {}
}

说明:在XUI入站列表中添加3个节点,端口分别是12881、12882、12883,配置模板中的出站项添加3段对应服务器上已绑定的多个IP地址(1.1.1.1、1.1.1.2、1.1.1.3)、自定义TAG是ip1/ip2/ip3,路由项通过入站TAG串联至自定义的出站TAG即可;

   示例2 :socks5代理做出口

{
  "api": {
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService"
    ],
    "tag": "api"
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 62789,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "tag": "api"
    }
  ],
  "outbounds": [
    {
      "tag": "sk-hk",   
      "protocol": "socks",
      "settings": {
        "servers": [
          {
            "address": "12.35.26.88",   
            "ota": false,
            "port": 1568,  
            "users": [
              {
                "user": "usertest", 
                "pass": "passwdtest"
              }
            ]
          }
        ]
      }
     },
    {
      "protocol": "freedom",
      "settings": {}
    },
    {
      "protocol": "blackhole",
      "settings": {},
      "tag": "blocked"
    }
  ],
  "policy": {
    "system": {
      "statsInboundDownlink": true,
      "statsInboundUplink": true
    }
  },
  "routing": {
    "rules": [
     {
        "inboundTag": [
          "inbound-12668"
        ],
        "outboundTag": "sk-hk",
        "type": "field"
      },
      {
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api",
        "type": "field"
      },
      {
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "blocked",
        "type": "field"
      },
      {
        "outboundTag": "blocked",
        "protocol": [
          "bittorrent"
        ],
        "type": "field"
      }
    ]
  },
  "stats": {}
}

 说明:出站项新增一段socks代理配置,address处填socks的IP地址、port填端口、user内分别填用户和密码、无用户密码则把“[”括号内留空,再通过路由指定12668入站节点走这个socks代理出站;

   示例3 :自定义出口域名分流

{
  "api": {
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService"
    ],
    "tag": "api"
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 62789,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "sniffing": {
      "enabled": true, 
      "destOverride": ["http", "tls"]
      },
      "tag": "api"
    }
  ],
  "outbounds": [
    {
      "tag": "sk-hk",   
      "protocol": "socks",
      "settings": {
        "servers": [
          {
            "address": "12.35.26.88",   
            "ota": false,
            "port": 1568,  
            "users": [
              {
                "user": "usertest", 
                "pass": "passwdtest"
              }
            ]
          }
        ]
      }
     },
    {
      "protocol": "freedom",
      "settings": {}
    },
    {
      "protocol": "blackhole",
      "settings": {},
      "tag": "blocked"
    }
  ],
  "policy": {
    "system": {
      "statsInboundDownlink": true,
      "statsInboundUplink": true
    }
  },
  "routing": {
    "rules": [
     {
        "type": "field",
        "outboundTag": "sk-hk",
        "domain": ["geosite:netflix","openai.com"]
      },
      {
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api",
        "type": "field"
      },
      {
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "blocked",
        "type": "field"
      },
      {
        "outboundTag": "blocked",
        "protocol": [
          "bittorrent"
        ],
        "type": "field"
      }
    ]
  },
  "stats": {}
}

 说明:跟示例2一样的配置,但是在路由处则不是单独针对某个节点应用,而是匹配路由规则进行分流至socks代理出口,比如其中的Netflix GEO文件名和openai域名,当通过域名匹配时需在入站项开启流量嗅探功能,同时匹配规则需写全、以上仅为示例;比如openai网站使用的域名和接口有openai.com、cdn.auth0.com、azureedge.net等十几条域名规则。

0

评论 (8)

取消
  1. 头像
    菜鸟
    Windows 10 · Google Chrome

    你好,如果想添加多个socks5代理做出口,然后每个节点单独对应固定的socks5 ip,该如何写呢

    回复
    1. 头像
      sockat 作者
      Windows 10 · Google Chrome
      @ 菜鸟

      通过上面的模板做多个socks出口,然后路由串联好tag就行了

      回复
      1. 头像
        菜鸟
        Windows 10 · Google Chrome
        @ sockat

        {
        "api": {
        "services": [
        "HandlerService",
        "LoggerService",
        "StatsService"
        ],
        "tag": "api"
        },
        "inbounds": [
        {
        "listen": "127.0.0.1",
        "port": 62789,
        "protocol": "dokodemo-door",
        "settings": {
        "address": "127.0.0.1"
        },
        "tag": "api"
        }
        ],
        "outbounds": [
        {
        "tag": "ip1",
        "protocol": "socks",
        "settings": {
        "servers": [
        {
        "address": "X.X.X.X",
        "port": 56851,
        "users": [
        {
        "user": "XXX",
        "pass": "XXX"
        }
        ]
        }
        ]
        }
        },
        {
        "tag": "ip2",
        "protocol": "socks",
        "settings": {
        "servers": [
        {
        "address": "X.X.X.X.",
        "port": 12324,
        "users": [
        {
        "user": "XXX",
        "pass": "XXX"
        }
        ]
        }
        ]
        }
        },
        {
        "protocol": "blackhole",
        "settings": {},
        "tag": "blocked"
        }
        ],
        "policy": {
        "system": {
        "statsInboundDownlink": true,
        "statsInboundUplink": true
        }
        },
        "routing": {
        "rules": [
        {
        "inboundTag": [
        "inbound-10010"
        ],
        "outboundTag": "ip1",
        "type": "field"
        },
        {
        "inboundTag": [
        "inbound-10020"
        ],
        "outboundTag": "ip2",
        "type": "field"
        },
        {
        "inboundTag": [
        "api"
        ],
        "outboundTag": "api",
        "type": "field"
        },
        {
        "ip": [
        "geoip:private"
        ],
        "outboundTag": "blocked",
        "type": "field"
        },
        {
        "outboundTag": "blocked",
        "protocol": [
        "bittorrent"
        ],
        "type": "field"
        }
        ]
        },
        "stats": {}
        }

        回复
        1. 头像
          菜鸟
          Windows 10 · Google Chrome
          @ 菜鸟

          我是这么写的,但是这样游戏里的延迟就非常高,感觉没走中转一样,如果只用一个socks出口的话,延迟又是正常的,能否指点下哪里不对

          回复
          1. 头像
            sockat 作者
            Windows 10 · Google Chrome
            @ 菜鸟

            网络能正常用说明配置没问题,单游戏加速不是特别清楚,这个得看xray的处理方法

            回复
  2. 头像
    大浩瀚
    Windows 10 · Google Chrome

    作者你好,我是用“出站项新增一段socks代理配置,address处填socks的IP地址、port填端口、user内分别填用户和密码、无用户密码则把“[”括号内留空,再通过路由指定12668入站节点走这个socks代理出站”这一条,最后不止是12688端口的流量走了socks出站,直接是全部节点都走了socks出站,能给解答一下吗?

    回复
    1. 头像
      123
      Windows 10 · Google Chrome
      @ 大浩瀚

      要在最后将所有的 TCP 和 UDP 流量默认路由到 “direct” 出站,即使用 VPS 本身的 IP 访问

      回复
  3. 头像
    123
    Windows 10 · Google Chrome

    牛逼大佬,通过你的文章终于解决x-ui的问题了,可以愉快地上网了

    回复