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

160 天前
 liuweiqing

宿主机使用 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

1308 次点击
所在节点    OpenWrt
9 条回复
chenset
160 天前
大概需要再创建一个 macvlan 虚拟网卡, 然后让宿主机跟 macvlan 的容器借助新创建的虚拟网卡走独立的 macvlan 网络.
有做这个吗?
liuweiqing
160 天前
@chenset 做了,宿主机可以直接请求到 openwrt 的网页内容
chenset
160 天前
@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
160 天前
然后可以再打印一下路由表。route -n
mayli
160 天前
Macvlan 的缺点就是宿主机没法直接访问…
liuweiqing
160 天前
@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
160 天前
我们的第一行不一样, 看看是不是这里了.
你的默认网关走 enp1s0, 我的默认网关走 macvlan

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

我的:
default via 10.0.0.4 dev macvlan2host
liuweiqing
160 天前
@chenset 天哪,成功了,谢谢大佬
liuweiqing
160 天前
@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

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1077817

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX