You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker MacVlan与IPvlan网络配置异常问题求助

Docker MacVlan与IPvlan网络配置问题求助

1. 已成功配置Macvlan桥接模式

执行以下命令配置宿主机虚拟网卡:

sudo ip link add macvlan_int link enp0s3 type macvlan mode bridge
sudo ip address add 192.168.1.2/24 dev macvlan_int
sudo ip link set macvlan_int up
sudo ip route add 192.168.1.110/32 dev macvlan_int

使用如下docker-compose配置后,容器IP 192.168.1.110 可正常通过浏览器访问:

version:'3.8'
service:
    profiles:
      - net7
    image: nginx
    networks:
     demo-macvlan:
      ipv4_address:  192.168.1.110
    stdin_open: true
    tty: true
    restart: 'no'
    init: true

networks:
  demo-macvlan:
    driver: macvlan
    ipam:
      config:
        - subnet: 192.168.1.0/24 
          gateway: 192.168.1.1 
    driver_opts:
      parent: enp1s0

2. Macvlan 802.1Q中继桥接模式配置异常

使用如下docker-compose配置后,容器内ping自身IP 192.168.1.130 正常,但宿主机无法ping通该IP,浏览器访问提示连接拒绝,已排查无IP冲突问题:

version:'3.8'
service:
  ivlan2:
    profiles:
      - net8
    image: nginx
    networks:
      ip-vlan:
        ipv4_address: 192.168.1.130
    stdin_open: true
    tty: true
    restart: 'no'
    init: true

networks:
  net-app:
   external: true
  net:
    external: true
  demo-macvlan50-net:
    driver: macvlan
    ipam:
      config:
      - subnet:  192.168.1.0/24 
        gateway: 192.168.1.1
    driver_opts:
      parent: enp1s0.50

3. IPvlan L2模式配置异常

使用如下配置后,容器内ping自身IP 192.168.1.110 正常,但宿主机无法访问该IP:

version: '3.8'

services:
  ivlan2:
    profiles:
      - "net9"
    image: nginx
    networks:
      ip-vlan:
        ipv4_address: 192.168.1.110
    stdin_open: true
    tty: true
    restart: 'no'
    init: true

networks:
  ip-vlan: 
    driver: ipvlan
    ipam:
      config:
        - subnet: 192.168.1.0/24
          gateway: 192.168.1.1
    driver_opts:
      parent: enp1s0
      mode: l2

恳请解答上述现象的原因,以及如何解决宿主机无法访问容器IP的问题。


内容的提问来源于stack exchange,提问作者Eduard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 12:32:20