配置系统环境 打开网卡混杂模式
1 ip link set eth0 promisc on
加载 PPPOE 内核模块
创建接口 1 2 3 4 5 docker network create -d macvlan \ --subnet=10.0.0.0/24 --gateway=10.0.0.1 \ --ipv6 --subnet=fe80::/16 --gateway=fe80::1 \ -o parent=eth0 \ macvlan
创建容器 下载OpenWrt镜像
1 docker pull dawn2000/openwrt:latest
创建并启动容器
1 2 3 4 5 6 7 8 docker run -d \ --restart always \ --net macvlan \ --cap-add NET_ADMIN \ --hostname OpenWrt \ --name openwrt \ openwrt:latest \ sh -c "echo -e 'search lan\nnameserver 127.0.0.1\nnameserver ::1' > /etc/resolv.conf && /sbin/init"
配置 OpenWrt 进入容器终端
1 docker exec -it openwrt /bin/sh
使用vi编辑 /etc/config/network
1 2 3 4 5 6 7 config interface 'lan' option type 'bridge' option ifname 'eth0' option proto 'static' option ipaddr '10.0.0.1' option netmask '255.255.255.0' option ip6assign '60'
重启 openwrt 网络
1 /etc/init.d/network restart
宿主机出口 由于 docker 网络采用 macvlan 的 bridge 模式,即使宿主机与容器在同一网段,相互之间也是无法通信的。 为了解决这个问题,需利用多个 macvlan 接口之间是互通的原理,在 LAN 口新建一个 macvlan 虚拟接口。
使用vi编辑/etc/network/interfaces 并粘贴以下命令
1 2 3 4 5 6 7 8 auto macvlan iface macvlan inet static address 10.0.0.11 netmask 255.255.255.0 gateway 10.0.0.1 dns-nameservers 10.0.0.1 pre-up ip link add macvlan link eth0 type macvlan mode bridge post-down ip link del macvlan link eth0 type macvlan mode bridge