用树莓派和docker搭建软路由

$ curl -fsSL https://get.docker.com -o get-docker.sh

# 如果没有执行权限
$ chmod +x ./get-docker.sh

$ sudo ./get-docker.sh

(请勿在配置好软件源之前安装docker包)

$ curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add -

$ sudo add-apt-repository \
    "deb [arch=armhf] https://mirrors.aliyun.com/docker-ce/linux/raspbian \
    $(lsb_release -cs) \
    stable"
    
$ sudo apt-get update

$ sudo apt-get install docker-ce
sudo usermod -aG docker $USER
docker pull openwrt

--subnet参数为路由器地址,--gateway参数为树莓派的局域网ip

docker network create -d macvlan --subnet=192.168.124.0/24 --gateway=192.168.124.17 -o parent=eth0 macnet
docker run --restart always --name openwrt -d --network macnet --privileged   sulinggg/openwrt:rpi4 /sbin/init

通过docker exec -it openwrt bash进入容器后,执行vim /etc/config/network

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ipaddr '192.168.124.50'
        option gateway '192.168.124.1'
        option dns '192.168.124.1'

ipaddr为openwrt分配地址,可以通过这个地址打开openwrt的web gui

gateway修改为局域网的网关地址

dns指定为路由器的地址

在浏览器中输入ipaddr的地址–本例中为192.168.124.50–以进入web gui

默认用户和密码分别是rootpassword

在你要使用软路由的设备上修改IPV4的配置

Related Content