V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
aries1998
V2EX  ›  Docker

docker macvlan 环境 nat ipv6 连不通外网

  •  
  •   aries1998 · 352 天前 · 1055 次点击
    这是一个创建于 352 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Host: 一台 x86 的 ubuntu 做的路由, 桥接光猫拨号
    eth0: 连光猫 192.168.1.0/24
    eth1: 内网连交换器 192.168.0.0/24
    wide-dhcp6c + dnsmasq 获取 slaac 地址和 ra 广播,路由以及内网机器外网 ipv6 都正常获取。

    docker 配置:
    cat /etc/docker/daemon.json
    {
    "data-root":"/data/docker",
    "bip": "10.20.0.1/16",
    "ipv6": true,
    "fixed-cidr-v6": "fd00:5::/80",
    "ip6tables": true,
    "experimental": true
    }

    bridge network 方式的 container 通过 ipv6 nat 方式能访问 ipv6 外部网络



    macvlan 配置步骤:
    docker network create -d macvlan --subnet=192.168.0.0/24 --ip-range=192.168.0.192/26 --gateway=192.168.0.10 --ipv6 --subnet=fd00:8::/80 --gateway=fd00:8::1 -o macvlan_mode=bridge -o parent=eth1 macnet
    ip link add macvlan link eth1 type macvlan mode bridge
    ip addr add 192.168.0.10/24 dev macvlan
    ip -6 addr add fd00:8::1 dev macvlan
    ifconfig macvlan up
    ip route add 192.168.0.192/26 dev macvlan
    ip -6 route add fd00:8::/80 dev macvlan

    测试 container
    docker run -d --restart=always --net=macnet --ip=192.168.0.254 --name=mtool_vlan praqma/network-multitool


    container 内部 ip 地址:
    eth0 Link encap:Ethernet HWaddr 02:42:C0:A8:00:FE
    inet addr:192.168.0.254 Bcast:192.168.0.255 Mask:255.255.255.0
    inet6 addr: fe80::42:c0ff:fea8:fe/64 Scope:Link
    inet6 addr: fd00:8::2/80 Scope:Global
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:65 errors:0 dropped:0 overruns:0 frame:0
    TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:17957 (17.5 KiB) TX bytes:2356 (2.3 KiB)


    具体问题如下:
    fd00:8::2 ping 的通 fd00:8::1
    fd00:8::2 ping 不通 host 里 macvlan 以外的其他 ipv6 网络
    内网 192.168.0.0/24 网段的能 ping 通 fd00:8::1 , ping 不通 fd00:8::2
    bridge 网络 fd00:5::/80 的 container 能 ping 通 fd00:8::2, 但反过来不行, 这点我是最不能理解的

    host 上面的内核设置, 路由,以及 iptables SNAT 规则都检查了,应该没问题,一来这台 host 一直跑主路由, 二来 bridge 模式的 container 能 nat ipv6 方式访问外网,macvlan 的 ipv6 我也是配置的 nat 方式, 两者应该没什么区别。
    第 1 条附言  ·  351 天前
    macvlan 的 container 能 ping 通 host 上面所有的 global ipv6 地址, 但就是出不去 host
    第 2 条附言  ·  351 天前
    最后发现是 docker 默认会把 FORARD 链的 policy 改为 DROP ,但是目前发现只改了 ipv6 ,没改 ipv4 ,不知道为什么
    3 条回复    2023-05-11 08:47:44 +08:00
    paranoiagu
        1
    paranoiagu  
       352 天前 via Android
    容器直接获取 ipv6 公网 ip ,不要通过路由器 nat
    luckjoe680
        2
    luckjoe680  
       352 天前
    docker ipv6 只能 host 吧?
    aries1998
        3
    aries1998  
    OP
       352 天前
    @paranoiagu 试过直接 slaac 方式,container 能拿到 ipv6 ,但也访问不了外网,有点怀疑跟 nat 方式不通是一样原因。 另外直接拿外网 ip 又要搞防火墙,太麻烦,还是得用 nat 方式。

    @luckjoe680 好像没这种说法
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   910 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:56 · PVG 03:56 · LAX 12:56 · JFK 15:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.