树莓派中利用docker搭建openwrt旁路由
注意需要先查看内核信息(需要是aarch64)
uname -m
1.查询当前网卡名称(以下均以网卡名eth0为例,请注意替换)
ifconfig
2.打开网卡混杂模式
ip link set eth0 promisc on
3.创建虚拟网络
docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.1 -o parent=eth0 macnet
4.拉取openwrt镜像
docker pull unifreq/openwrt-aarch64:latest
拉取完毕之后查看一下拉取结果
docker images
5.创建并运行openwrt容器(创建openwrt_start.sh脚本)
#!/bin/bash
IP="192.168.0.200" #旁路由ip地址
MACADDR="02:42:C0:A8:00:02" #MAC地址,随机生成
IMG_TAG=latest
KERNEL_VERSION=$(uname -r)
docker run \
--name openwrt-${IMG_TAG} \
--restart always \
--network macnet \
--mac-address ${MACADDR} \
--ip ${IP} \
-d \
--privileged=true \
--ulimit nofile=16384:65536 \
-v /lib/modules/${KERNEL_VERSION}:/lib/modules/${KERNEL_VERSION} \
unifreq/openwrt-aarch64:$IMG_TAG
6.查看openwrt容器运行状态,如果STATUS是UP则说明运行成功
docker ps -a
7.进入openwrt容器
docker exec -it openwrt /bin/sh
8.编辑配置文件
vim /etc/config/network
修改lan口内容
config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.0.100'
option netmask '255.255.255.0'
option ip6assign '60'
option gateway '192.168.0.1'
option broadcast '192.168.0.255'
option dns '192.168.0.1'
9.重启网络
/etc/init.d/network restart