

1、打开网卡混杂模式
sudo ip link set eth0 promisc on
2.创建网络
sudo ifconfig 或者 ip addr ip router|grep default #查看自己的网口名称 eth0或者别的
(须结合实际网络情况,不能照抄命令)
sudo docker network create -d macvlan \
--subnet=192.168.0.0/24 \
--gateway=192.168.0.1 \
-o parent=eth0 \
-o macvlan_mode=bridge \
macnet
3.拉取openwrt镜像(根据需求)
sudo docker pull sulinggg/openwrt:rpi3 # 下载树莓派3/3B的docker镜像
sudo docker pull sulinggg/openwrt:rpi4 # 下载树莓派4B的docker镜像
sudo docker pull sulinggg/openwrt:86_64 # 下载64位台式机的docker镜像
sudo docker pullregistry.cn-shanghai.aliyuncs.com/suling/openwrt:latest #阿里云下载最新版本的
sudo docker images #查看已经下载的镜像
4.创建并启动容器
sudo docker run --restart always --name openwrt -d --network macnet --privileged sulinggg/openwrt:rpi3 /sbin/init #树莓派3B
sudo docker run --restart always --name openwrt -d --network macnet --privileged sulinggg/openwrt:86_64 /sbin/init #X86台式机
5.进入容器并修改相关参数
(须结合实际网络情况,不能照抄配置)
sudo docker exec -it openwrt bash #进入openwrt 容器的SSH
nano /etc/config/network #修改openwrt网络设置
----------------------------------------
#以下无需更改
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
#以下无需更改
config globals 'globals'
#根据需求更改
config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option netmask '255.255.255.0'
option ipaddr '192.168.0.100' #这里
option gateway '192.168.0.1' #这里
option dns '223.5.5.5 223.6.6.6' #这里
#以下无需更改
config interface 'vpn0'
option ifname 'tun0'
option proto 'none'
-------------------------------------
ctrl+o 保存 ctrl+x 退出
6、重启网络并检查
/etc/init.d/network restart #重启openwrt的网络
ip addr #检查网络设置
exit #退出docker里的openwrt的ssh
7、解决树莓派网卡重启后的混杂丢失问题
sudo nano /etc/dhcpcd.conf
------------------------------------------------------------------------
#去掉注释部分根据需求更改
# Example static IP configuration:
interface eth0
static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
#最后添加
auto macvlan
iface macvlan inet static
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.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
8、登录openwrt后台地址
192.168.0.100
password
网络-防火墙 修改 转发 接受
网络-接口-LAN 修改 ipv6禁用 添加几个dns 223.5.5.5 114.114.114.114 8.8.8.8
物理设置
9、一定要断电重启树莓派