Skip to content

Instantly share code, notes, and snippets.

@imerr
Last active August 21, 2023 23:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?

Revisions

  1. imerr revised this gist Aug 21, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    @@ -31,5 +31,5 @@ docker run -it --network ip6net debian:stable bash
    # in the container:
    apt update
    apt install curl
    # this should give different ips!
    # this should give different ips if run multiple times
    curl https://ipv6.icanhazip.com
  2. imerr revised this gist Aug 21, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.sh
    @@ -14,7 +14,7 @@ echo '{
    systemctl restart docker # or reboot if there's kernel updates anyways..

    # assuming this is a /64
    IPBLOCK="2a01:4f9:c012:9823"
    IPBLOCK="1234:dead:beef:4321"
    # add a v6 docker network
    docker network create --ipv6 -o "com.docker.network.bridge.enable_ip_masquerade=false" --subnet $IPBLOCK:1::/80 ip6net

    @@ -31,5 +31,5 @@ docker run -it --network ip6net debian:stable bash
    # in the container:
    apt update
    apt install curl
    # this should give 20 different ips!
    for i in {1..20}; do curl https://ipv6.icanhazip.com; done
    # this should give different ips!
    curl https://ipv6.icanhazip.com
  3. imerr renamed this gist Aug 19, 2023. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions gistfile1.txt → gistfile1.sh
    @@ -1,3 +1,5 @@
    # this is assuming install on a fresh debian VM, on an existing system you may want to adjust/skip things
    # get system up-to-date and install docker (in the future you may want dockers apt repo)
    apt update && apt upgrade -y && apt install docker.io apparmor -y
    # docker config, the log stuff isn't needed but should be configured anyways
    echo '{
    @@ -9,16 +11,22 @@ echo '{
    "max-file": "10"
    }
    }' > /etc/docker/daemon.json
    systemctl restart docker
    systemctl restart docker # or reboot if there's kernel updates anyways..

    # assuming this is a /64
    IPBLOCK="2a01:4f9:c012:9823"
    # add a v6 docker network
    docker network create --ipv6 -o "com.docker.network.bridge.enable_ip_masquerade=false" --subnet $IPBLOCK:1::/80 ip6net
    # make ipv4 nat work since enable_ip_masquerade makes docker not do ipv4 stuff..

    # WARNING: below iptables steps don't persist so need to be ran every boot (iptables-save to the rescue!)

    # JANK: make ipv4 nat work since enable_ip_masquerade makes docker not do ipv4 stuff..
    # this will potentially break things if there's other docker networks running since docker usually hands out 172.x.0.0/16
    iptables -t nat -A POSTROUTING -s 172.0.0.0/8 ! -o docker0 -j MASQUERADE
    # IPv6 SNAT to make it use a random ip from the whole range :)
    ip6tables -t nat -A POSTROUTING -s "$IPBLOCK:1::/80" -j SNAT --to-source $IPBLOCK:2::0-$IPBLOCK:ffff:ffff:ffff:ffff

    # TEST if stuff works
    docker run -it --network ip6net debian:stable bash
    # in the container:
    apt update
  4. imerr revised this gist Aug 19, 2023. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions gistfile1.txt
    @@ -1,22 +1,27 @@
    # cat /etc/docker/daemon.json
    {
    apt update && apt upgrade -y && apt install docker.io apparmor -y
    # docker config, the log stuff isn't needed but should be configured anyways
    echo '{
    "experimental": true,
    "ip6tables": true,
    "log-driver": "json-file",
    "log-opts": {
    "max-size": "10m",
    "max-file": "10"
    }
    }
    }' > /etc/docker/daemon.json
    systemctl restart docker

    # assuming this is a /64
    IPBLOCK="2a01:4f9:c012:9823"
    docker network create --ipv6 -o "com.docker.network.bridge.enable_ip_masquerade=false" --subnet $IPBLOCK:1::/80 ip6net
    # tell the host we should respond on all of the /64
    # not sure if this is needed
    ip route add local $IPBLOCK::/64 dev lo
    # make ipv4 nat work since enable_ip_masquerade makes docker not do ipv4 stuff..
    # this will potentially break things if there's other docker networks running since docker usually hands out 172.x.0.0/16
    iptables -t nat -A POSTROUTING -s 172.0.0.0/8 ! -o docker0 -j MASQUERADE
    # IPv6 SNAT to make it use a random ip from the whole range :)
    ip6tables -t nat -A POSTROUTING -s "$IPBLOCK:1::/80" -j SNAT --to-source $IPBLOCK:2::0-$IPBLOCK:ffff:ffff:ffff:ffff
    docker run -it --network ip6net debian:stable bash
    # in the container:
    apt update
    apt install curl
    # this should give 20 different ips!
    for i in {1..20}; do curl https://ipv6.icanhazip.com; done
  5. imerr created this gist Aug 18, 2023.
    22 changes: 22 additions & 0 deletions gistfile1.txt
    @@ -0,0 +1,22 @@
    # cat /etc/docker/daemon.json
    {
    "experimental": true,
    "ip6tables": true,
    "log-driver": "json-file",
    "log-opts": {
    "max-size": "10m",
    "max-file": "10"
    }
    }
    # assuming this is a /64
    IPBLOCK="2a01:4f9:c012:9823"
    docker network create --ipv6 -o "com.docker.network.bridge.enable_ip_masquerade=false" --subnet $IPBLOCK:1::/80 ip6net
    # tell the host we should respond on all of the /64
    # not sure if this is needed
    ip route add local $IPBLOCK::/64 dev lo
    # IPv6 SNAT to make it use a random ip from the whole range :)
    ip6tables -t nat -A POSTROUTING -s "$IPBLOCK:1::/80" -j SNAT --to-source $IPBLOCK:2::0-$IPBLOCK:ffff:ffff:ffff:ffff
    docker run -it --network ip6net debian:stable bash
    apt update
    apt install curl
    for i in {1..20}; do curl https://ipv6.icanhazip.com; done