Skip to content

Instantly share code, notes, and snippets.

@metathrone
Forked from BlackHacked/readme.md
Created March 13, 2023 14:22
Show Gist options
  • Save metathrone/4e001b5a0c39812c302fb6f891de18be to your computer and use it in GitHub Desktop.
Save metathrone/4e001b5a0c39812c302fb6f891de18be to your computer and use it in GitHub Desktop.
n1 docker openwrt

镜像构建

FROM scratch
ADD openwrtmix-n1-R20.2.15-rootfs.tar.gz /
RUN mkdir /var/lock
USER root
CMD /sbin/init

食用方法

这个镜像在小钢炮的docker上构建

按步骤在ssh输入以下命令即可在N1上搭建好

  • 第一步:获取docker镜像 docker pull startwish/n1-openwrtmix:latest

  • 第二步:打开网卡的混杂模式 ip link set eth0 promisc on

  • 第三步:给docker创建网络 docker network create -d macvlan --subnet=192.168.2.0/24 --gateway=192.168.2.1 -o parent=eth0 macnet 其中的192.168.2.0/24是我主路由的网段,192.168.2.1是我主路由的IP地址,也就是网关地址,这两个根据自己的实际情况修改

  • 第四步:创建容器 docker run --name openwrtmix --restart always -d --network macnet --privileged startwish/n1-openwrtmix:latest /sbin/init 其中的--name后的openwrtmix是容器名字,可以自行修改。用这条命令创建容器后,容器开机自启,并且启动后会自动启动面板和环境。

  • 第五步:调整网络设置 在web ui上连接创建好的容器,输入


vi /etc/config/network 按以下模板修改lan部分内容(IP、网段的设置以实际情况修改)

config interface 'lan'
    option type 'bridge'
    option ifname 'eth0'
    option proto 'static'
    option ipaddr '192.168.2.3'
    option netmask '255.255.255.0'
    option gateway '192.168.2.1'
    option dns '192.168.2.1'
    

修改完成后保存,并重启网络服务


/etc/init.d/network restart 信息 账号root 密码password

宿主机跟旁路不通的问题 解决方案是修改/etc/network/interfaces文件:(谨慎操作)

iface eth0 inet manual
up ip link set eth0 promisc on
auto macvlan
iface macvlan inet static
   address 192.168.12.104→修改成你需要的
   netmask 255.255.255.0
   gateway 192.168.12.1→需改成你的主路由ip或192.168.12.5(旁路由的ip)
   dns-nameservers 192.168.12.1→需改成你的主路由ip或12.5或再加1个公共dns比如114
   pre-up ip link add macvlan link eth0 type macvlan mode bridge
   post-down ip link del macvlan link eth0 type macvlan mode bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment