讓花成花 讓我成我

Docker出口使用不同公网IP

iptables方法

iptables -t nat -I POSTROUTING -s 172.18.0.10 ! -o docker1 -j SNAT --to 192.168.0.100
# 172.18.0.10 = 容器ip
# docker1 = docker network网卡 
# 192.168.0.100 = 公网ip 这里为VPC IP

容器自定义IP不能使用默认的docker0 network

ipvlan方法

docker network create -d ipvlan \
    --subnet=192.168.0.0/24 \
    --gateway=192.168.0.1 \
    -o ipvlan_mode=l2 \
    -o parent=ens3 docker1

将公网ip直接接入容器,与宿主机同MAC

缺点:主机无法再使用此公网ip

Docker出口使用不同公网IP

https://llb.im/posts/22.html

作者

Qin

发布时间

2024-05-23

许可协议

CC BY 4.0

添加新评论