前期准备#
开启网卡混合模式
sudo ip link set enx00e04c6800fa promisc on
创建 macvlan 网络
docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=enx00e04c6800fa macnet
pull docker
docker pull registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64
配置 docker#
运行 docker
docker run --restart always --name openwrt -d --network macnet --privileged registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64 /sbin/init
进入 docker 设置网络
docker exec -it openwrt bash
vim /etc/config/network
更改 Lan 口设置:
config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.50.100'
option netmask '255.255.255.0'
option ip6assign '60'
option gateway '192.168.50.1'
option broadcast '192.168.50.255'
option dns '192.168.50.1'
重启网络
/etc/init.d/network restart
进行设置#
地址option ipaddr
用户名:root
密码:password
宿主机网络恢复#
Openwrt 容器运行后,宿主机内可能无法正常连接外部网络,需要修改宿主机的 /etc/network/interfaces
文件
cp /etc/network/interfaces /etc/network/interfaces.bak
vim /etc/network/interfaces
向文件末尾添加:
auto eth0
iface eth0 inet manual
auto macvlan
iface macvlan inet static
address 192.168.50.200
netmask 255.255.255.0
gateway 192.168.50.1
dns-nameservers 192.168.50.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