抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

OpenWrt 的妙用很多,本文介绍如何使用 Docker 快速安装 OpenWrt

Docker 的安装和如何使用不再赘述

一、准备工作

1. 查看网络信息

找到实际的网卡信息,一般命名为 eth0/eno1-ovs ,IP地址为 192.168.x.x

1
2
3
4
5
$ ip a                           
5: eno1-ovs: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether a8:a1:59:xx:0f:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.5.5/24 brd 192.168.5.255 scope global noprefixroute eno1-ovs
valid_lft forever preferred_lft forever

2. 开启网卡混杂模式

请注意将命令中的 eno1-ovs 替换为你的实际网卡名称,有的可能为 eth0

1
sudo ip link set eno1-ovs promisc on

3. 创建 docker macvlan 网卡

  • 清注意将命令中 192.168.5.0192.168.5.15 替换为你的实际网段,有的可能为 192.168.2.x
  • 请注意将命令中 eno1-ovs 替换为你实际网卡名称,有的可能为 eth0
1
sudo docker network create -d macvlan --subnet=192.168.5.0/24 --gateway=192.168.5.1 -o parent=eno1-ovs macnet

二、部署 OpenWrt

1.修改配置

执行 docker compose up -d 启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
services:
openwrt:
# 若你的设备为arm或树莓派等,可以查看符合你硬件的镜像
# https://github.com/SuLingGG/OpenWrt-Docker/blob/master/README.md#openwrt-%E6%A0%87%E5%87%86%E9%95%9C%E5%83%8F
image: sulinggg/openwrt:x86_64
container_name: openwrt
restart: always
privileged: true
command: /sbin/init
networks:
macnet:

networks:
macnet:
external: true

2. 修改 openWrt 网络信息

镜像中默认的网络信息可能不符合你的实际网段 192.168.5.x 之类,执行命令进入容器内部

1
docker exec -it openwrt /bin/bash

并修改文件

1
vi /etc/config/network

将其中三处改为你实际信息,按 i 进入编辑模式,修改完按 :wq 保存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config globals 'globals'
option packet_steering '1'

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.5.6' # 此处 ipaddr 改为你 openwrt 的 IP,进入后台也是用这个ip
option gateway '192.168.5.1' # 此处 gateway 改为你路由器ip
option dns '192.168.5.1' # 此处 dns 改为你路由器ip

config interface 'vpn0'
option ifname 'tun0'
option proto 'none'

3. 重启 OpenWrt 网络生效

1
/etc/init.d/network restart

4. 访问 OpenWrt 后台

访问 http://192.168.5.6,其中地址改为你刚才配置的 openwrt 的 IP,默认登录信息是

1
2
用户名:root
密码:password

评论