V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
OpenWrt 是一个专门面向嵌入式设备的 Linux 发行版。你可以将 OpenWrt 支持的型号的嵌入式设备,比如各种路由器上的系统,换成一个有更多可能性可以折腾的 Linux 系统。
OpenWrt 官方网站
liuweiqing
V2EX  ›  OpenWrt

docker macvlan 运行 openwrt 后,其它机器都能使用 openwrt 作为网关,而宿主机不行,为什么

  •  
  •   liuweiqing · Oct 5, 2024 · 2124 views
    This topic created in 575 days ago, the information mentioned may be changed or developed.

    宿主机使用 openwrt 作为网关,且已经设置了 macvlan 的桥接访问 使用 ping 8.8.8.8 结果 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. From 192.168.0.11 icmp_seq=1 Destination Host Unreachable From 192.168.0.11 icmp_seq=2 Destination Host Unreachable

    但是可以通过使用 openwrt 的 http 代理来访问 如:curl -x http://192.168.0.188:10809 https://www.youtube.com

    9 replies    2024-10-06 15:24:13 +08:00
    chenset
        1
    chenset  
       Oct 5, 2024
    大概需要再创建一个 macvlan 虚拟网卡, 然后让宿主机跟 macvlan 的容器借助新创建的虚拟网卡走独立的 macvlan 网络.
    有做这个吗?
    liuweiqing
        2
    liuweiqing  
    OP
       Oct 5, 2024
    @chenset 做了,宿主机可以直接请求到 openwrt 的网页内容
    chenset
        3
    chenset  
       Oct 5, 2024   ❤️ 1
    @liuweiqing 是已经做了这个吗?

    ip link add macvlan2host link eth1 type macvlan mode bridge # eth1 改为自己的网卡
    ip addr add 10.0.0.111/32 dev macvlan2host # 给 macvlan2host link 网卡增加随便一个 IP
    ip link set macvlan2host up
    chenset
        4
    chenset  
       Oct 5, 2024   ❤️ 1
    然后可以再打印一下路由表。route -n
    mayli
        5
    mayli  
       Oct 6, 2024
    Macvlan 的缺点就是宿主机没法直接访问…
    liuweiqing
        6
    liuweiqing  
    OP
       Oct 6, 2024
    @chenset
    ip link add macvlan0 link enp1s0 type macvlan mode bridge # 注意重启后不保留
    ip addr add 192.168.0.198/24 dev macvlan0 # 分配在与容器相同子网内的 IP
    ip link set macvlan0 up
    ip route add 192.168.0.188 dev macvlan0
    路由表:
    default via 192.168.0.188 dev enp1s0 proto static metric 100
    172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
    172.24.0.0/16 dev zthnhmvzsx proto kernel scope link src 172.24.66.92
    192.168.0.0/24 dev macvlan0 proto kernel scope link src 192.168.0.198
    192.168.0.0/24 dev enp1s0 proto kernel scope link src 192.168.0.11 metric 100
    192.168.0.188 dev macvlan0 scope link

    谢谢大佬
    chenset
        7
    chenset  
       Oct 6, 2024   ❤️ 1
    我们的第一行不一样, 看看是不是这里了.
    你的默认网关走 enp1s0, 我的默认网关走 macvlan

    你的:
    default via 192.168.0.188 dev enp1s0 proto static metric 100

    我的:
    default via 10.0.0.4 dev macvlan2host
    liuweiqing
        8
    liuweiqing  
    OP
       Oct 6, 2024
    @chenset 天哪,成功了,谢谢大佬
    liuweiqing
        9
    liuweiqing  
    OP
       Oct 6, 2024
    @chenset
    路由表改成你说的了
    default via 192.168.0.188 dev macvlan0 metric 100
    172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
    172.24.0.0/16 dev zthnhmvzsx proto kernel scope link src 172.24.66.92
    192.168.0.0/24 dev macvlan0 proto kernel scope link src 192.168.0.198
    192.168.0.0/24 dev enp1s0 proto kernel scope link src 192.168.0.11 metric 100
    192.168.0.188 dev macvlan0 scope link
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1067 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 17:49 · PVG 01:49 · LAX 10:49 · JFK 13:49
    ♥ Do have faith in what you're doing.