dnomd343 / XProxy

虚拟旁路由网关,支持内网设备IPv4与IPv6双栈透明代理
MIT License
198 stars 28 forks source link

只配置ipv4可以吗? #10

Open Angel0726 opened 8 months ago

Angel0726 commented 8 months ago

只配置ipv4可以吗?如果可以,是不是直接把教程中ipv6的内容删掉就可以了

dnomd343 commented 8 months ago

是的,docker创建网络时不输入IPv6相关配置,或者关闭radvd相关选项均可。

Angel0726 commented 8 months ago

看下我的配置有问题吗

# 开启混杂模式,网卡按实际情况指定
$ ip link set eth0 promisc on

# 启用IPv6内核模块
$ modprobe ip6table_filter  #命令报错,只用ipv4是不是不用管

# 网络配置按实际情况指定
docker network create -d macvlan \
  --subnet=192.168.124.0/24 --gateway=192.168.124.1 \
  -o parent=eth0 macvlan  # 在eth0网

docker run --restart always \
  --privileged --network macvlan -dt \
  --ip 192.168.124.41 \
  --name xproxy --hostname xproxy \  # 可选,指定容器名称与主机名
  --volume /home/xproxy/:/xproxy/ \
  --volume /home/xproxy/naive:/usr/bin/naive \
  --volume /etc/timezone:/etc/timezone:ro \  # 以下两句可选,用于映射宿主机时区信息(容器内默认为UTC0时区)
  --volume /etc/localtime:/etc/localtime:ro \
  dnomd343/xproxy:latest
Angel0726 commented 8 months ago
asset:
  update:
    cron: "0 5 6 * * *"
    proxy: "socks5://127.0.0.1:1080"  # 通过代理下载 Github 文件
    url:
      geoip.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
      geosite.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
network:
  dev: eth0
  dns:
    - 192.168.124.1
  ipv4:
    gateway: 192.168.124.1
    address: 192.168.124.41/24
  bypass:
    - 169.254.0.0/16
    - 224.0.0.0/3
    - fc00::/7
    - fe80::/10
    - ff00::/8
  exclude:
    - 192.168.124.1
proxy:
# 以下配置仅为示范
  bin: xray
  log: info
  socks:
    proxy4: 1094
    direct4: 1084
  sniff:
    enable: true
    redirect: true
# 以下配置仅为示范
dhcp:
  ipv4:
    enable: false

custom:
  pre:
    - nohup naive -c config/naive.json >> log/naive.log 2>&1 &
Angel0726 commented 8 months ago

outbound.json文件

{
    "outbounds": [
        {
            "tag": "direct4",
            "protocol": "freedom",
            "settings": {
                "domainStrategy": "UseIPv4"
            }
        },
        {
            "tag": "direct6",
            "protocol": "freedom",
            "settings": {
                "domainStrategy": "UseIPv6"
            }
        },
        {
            "tag": "naive",
            "protocol": "socks",
            "settings": {
                "servers": [
                    {
                        "address": "127.0.0.1",
                        "port": 1080
                    }
                ]
            }
        },
        {
            "tag": "hysreria",
            "protocol": "socks",
            "settings": {
                "servers": [
                    {
                        "address": "127.0.0.1",
                        "port": 10086
                    }
                ]
            }
        }
    ]
}
Angel0726 commented 8 months ago

routing.json

{
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "inboundTag": [
                    "direct4"
                ],
                "outboundTag": "direct4"
            },

            {
                "type": "field",
                "inboundTag": [
                    "proxy4"
                ],
                "domain": [
                    "geosite:cn"
                ],
                "outboundTag": "direct4"
            },

            {
                "type": "field",
                "inboundTag": [
                    "proxy4"
                ],
                "ip": [
                    "geoip:cn",
                    "geoip:private"
                ],
                "outboundTag": "direct4"
            },

            {
                "type": "field",
                "inboundTag": [
                    "proxy4"
                ],
                "outboundTag": "naive"
            }
        ]
    }
}
Angel0726 commented 8 months ago

宿主机中使用 docker network macvlan显示的容器ip地址 191.168.124.2
image docker中xproxy的地址 191.168.124.41 image 所以导致这个问题的原因是什么

Angel0726 commented 8 months ago

按照上述配置之后,发现网络无法连接,ping 外网、ping 内网都不行

dnomd343 commented 7 months ago

这个和ping无关,ICMP流量不会被代理。你需要将日志级别调整为 debug (目前是 info 级别),使用 docker logs -f xproxy 查看代理信息,确认流量是否被成功透明代理。

如果能确认代理成功,再来排查Xray的出站配置,如果没有相关请求信息,则需要排查透明代理配置。

Angel0726 commented 7 months ago

这个和ping无关,ICMP流量不会被代理。你需要将日志级别调整为 debug (目前是 info 级别),使用 docker logs -f xproxy 查看代理信息,确认流量是否被成功透明代理。

如果能确认代理成功,再来排查Xray的出站配置,如果没有相关请求信息,则需要排查透明代理配置。

有没有代理成功,ping baidu.com应该能ping通吧,ping不通代表网没通