前期準備#
開啟網卡混合模式
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