目录

香橙派5 Plus 上安装Openwrt系统,基于Docker

目录
  • 网络配置
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 配置成混杂模式
ip link set enP3p49s0 promisc on
ip link set enP4p65s0 promisc on

# ipv4转发
nano /etc/sysctl.conf
# 添加一行配置
net.ipv4.ip_forward = 1
# 或者将原文件中的net.ipv4.ip_forward = 1注释给取消
# 按esc+:,并输入wq保存文件后执行命令重新添加配置
sysctl -p /etc/sysctl.conf
  • 安装Docker/Openwrt
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# apt 安装
apt update && apt install docker

# 验证docker自启
systemctl list-unit-files | grep docker

# 打开自启动
systemctl enable docker.service

# OrangePi5或者其他armv8/aarch64的设备
docker pull sulinggg/openwrt:armv8
  • Docker Proxy
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 文件
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/proxy.conf

# 修改
[Service]
Environment="HTTP_PROXY=http://192.168.10.68:7890/"
Environment="HTTPS_PROXY=http://192.168.10.68:7890/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

# 重启容器
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo service docker restart
  • WAN的macvlan
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 查看是否支持
modprobe macvlan

# 创建WAN口的macvlan,名称为macnet0
docker network create -d macvlan --subnet=192.168.10.0/24 --gateway=192.168.10.1 -o parent=enP3p49s0 macnet0
# 注意,这里需要根据上述获取到的地址来配置(根据你的实际情况来填)。
# subnet字段对应端口所处的网络地址192.168.10.0/24,
# 其中的/24为子网掩码对应255.255.255.0;
# gateway字段对应默认网关192.168.10.1;
# parent对应网卡

# 可执行下方命令,验证是否创建成功
# 如果输出结果的NAME字段那一列有macnet0即成功。
# LAN端口的macvlan暂不创建。
docker network ls

# 开机
# --restart always为开机自启
# --network macnet0为我们刚才创建的WAN端口的macvlan
# --ip 192.168.10.100是为容器分配的ip地址,这里需要注意网段与enP3p49s0获取的一致,并且不能够冲突(也就是说当前网络下不能有其他设备的地址为192.168.10.100)。需根据自己的实际情况来配置。
# --privileged为特权模式
# --name openwrt容器名称为openwrt
# sulinggg/openwrt:armv8对应刚才获取的镜像。如果你的设备是树莓派,并且是按照我文章上方的命令获取的,则此处为sulinggg/openwrt:latest。其他设备则须根据你获取的镜像来写。
docker run -d --restart always --network macnet0 --ip 192.168.10.4 --privileged --name openwrt sulinggg/openwrt:armv8 /sbin/init
  • 进openwrt配网
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 进入 exit退出
docker exec -it openwrt bash

# 配网
nano /etc/config/network

config interface 'lan'
        option type 'bridge'
        option ifname 'enP3p49s0'
        option proto 'static'
        option ipaddr '192.168.10.4'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option gateway '192.168.10.1'
        option broadcast '192.168.10.255'
        option dns '192.168.10.1'

# ipaddr后的地址与Docker容器分配的地址一致
# netmask后为之前获取的子网掩码
# gateway后为之前获取的默认网关
# broadcast后为广播地址,改成同一网段
# dns后为dns地址,此处保持与默认网关一致

# 重启
/etc/init.d/network restart

# 若WAN没添加成功,则应给其添加一个ip地址
ip addr add 192.168.10.4/24 dev eth0

# 启用网卡?
sudo ifconfig eth0 up
  • LAN的macvlan
1
2
3
4
5
# 创建LAN端口macvlan,名称为macnet1
docker network create -d macvlan --subnet=192.168.22.0/24 --gateway=192.168.22.1 -o parent=enP4p65s0 macnet1

# 容器加入网络
docker network connect macnet1 openwrt
  • openclash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 进入内核安装目录
cd /etc/openclash/core/ 

# 下载内核安装包
wget https://github.com/vernesong/OpenClash/releases/download/Clash/clash-linux-armv8.tar.gz

# 解压内核安装包
tar -zxvf clash-linux-armv8.tar.gz

# 给予最高权限
chmod 777 clash