0%

N1小钢炮使用docker运行openwrt做旁路由

前言

N1刷入小钢炮系统后,使用其中的docker工具运行openwrt做旁路由,方便切换不同op版本。

步骤

启动docker

到小钢炮的后台启动[2],到System中的Startup里启动Docker:

点击Apps--->Other--->Docker Settings中的Install or Re-Install Docker UI,进行自动安装:

如果自动安装不上,参考链接[3],进行手动安装Docker UI,根据该链接中配置类似如下的/etc/docker/dameon/json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"experimental": true,
"ip": "0.0.0.0", #### 修改为host机局域网实际的IP以方便在portainer中点击
"graph": "/var/lib/docker",
"default-ulimits": {
"nofile": {
"Name": "nofile",
"Hard": 16384,
"Soft": 16384
}
},
"registry-mirrors": [
"https://xxxxxx.mirror.aliyuncs.com" #### 访问 https://cr.console.aliyun.com/ 进行开通 (免费)
],
"storage-driver": "overlay2"
}

部署docker版op[1]

假设已有编译好的openwrt-armvirt-64-default-rootfs.tar.gz,注意将下面的192.168.1.0和192.168.1.1改为你的主路由网段和ip:

1
2
3
4
5
6
# R20.3.25代表版本号或日期
docker import openwrt-armvirt-64-default-rootfs.tar.gz openwrt:R20.3.25
ip link set eth0 promisc on # 打开网卡混杂模式[4],以下三条命令(包含这行)除非刷机,否则只需执行一次
modprobe pppoe # 运行失败:modprobe: module pppoe not found in modules.dep
docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 macnet
docker run --restart always -d --network macnet --privileged openwrt:R20.3.25 /sbin/init

登陆portainer管理页面,找到Dashboard--->Contaners--->Image名称为openwrt:R20.3.25的,点击下方红色箭头的位置,然后点击connect:

Connect到命令行后,输入vi /etc/config/network,修改结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 ula_prefix 'fdb2:4c8c:1206::/48'

config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.1.119' # openwrt的地址
option netmask '255.255.255.0'
option ip6assign '60'
option gateway '192.168.1.1' # 主路由网关
option dns '192.168.1.1' # 主路由网关

配置完后Disconnect,在Containers里边选中openwrt,点击Restart

修改宿主机/etc/network/interfaces

/etc/network/interfaces修改为:

1
2
3
4
5
6
7
8
9
10
11
auto eth0
iface eth0 inet manual

auto macvlan
iface macvlan inet static
address $宿主机IP
netmask 255.255.255.0
gateway $openwrt IP
dns-nameservers $openwrt IP
pre-up ip link add macvlan link eth0 type macvlan mode bridge
post-down ip link del macvlan link eth0 type macvlan mode bridge

重启宿主机。

已知问题

  1. 小钢炮 Docker 安装 Openwrt 后,电脑不能 访问小钢炮 samba 的共享文件夹。

    解决方法:

    登入 docker 下的 openwrt,系统→挂载点→全部取消勾选,然后保存并应用。之后就不会与小钢炮的挂载冲突。

  2. 部分op的/etc/resolv.conf 文件dns参数有问题显示为127.0.0.11,可能会导致op加载慢或解析问题,解决方法,在op管理页-系统-启动项-本地启动脚本(或者在命令行界面修改/etc/rc.local)加入以下代码:

    1
    2
    3
    4
    cat > /etc/resolv.conf <<EOF
    nameserver 127.0.0.1
    options ndots:0
    EOF
  3. 自己编译的op固件在docker中无法扶墙(刷机正常,就是docker不行),报错为:

    1
    2
    bash-4.4# /etc/init.d/shadowsocksr restart
    ssr-rules[13061]: Can't redirect, please check the iptables.

    尚未解决,目前用的n1_docker_精简版_梁非凡_注意先看固件说明_2020_3_30.7z这个镜像中的Hello World插件。

  4. vssr插件在适配的主题是这个,原生的页面显示有问题,以lean源openwrt为例,修改openwrt_ci.yml,在update feeds前增加自定义插件部分:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    - name: Customize plugins
    run: |
    cd package/lean/
    # 主题
    rm -rf luci-theme-argon
    git clone -b 18.06 https://github.com/jerrykuku/luci-theme-argon.git
    # vssr 插件
    git clone https://github.com/jerrykuku/lua-maxminddb.git
    git clone https://github.com/jerrykuku/luci-app-vssr.git

    - name: Update feeds
    run: |
    ./scripts/feeds update -a
    ./scripts/feeds install -a
    # 其它内容
    #。。。。。。。。
    #。。。。。。。。
    # 在配置文件中选择argon主题:
    # CONFIG_PACKAGE_luci-theme-argon=y

    启用主题:[系统]-->[系统]-->[语言和界面]-->[主题]

参考

[1] https://t.me/PIN1Group/702566

[2] https://gitee.com/8ox86/phicomm-n1-issue/wikis/docker%20ui%E6%89%8B%E5%8A%A8%E5%AE%89%E8%A3%85%E6%B3%95--%20%E7%BD%91%E7%BB%9C%E4%B8%8D%E5%A5%BD%E7%9A%84%E6%97%B6%E5%80%99%E4%BD%BF%E7%94%A8?sort_id=1554755

[3] https://xsinger.me/diy/1132.html

[4] https://mlapp.cn/376.html