(三)PVE LXC容器安装OpenWrt当主路由及插件安装

一. 准备工作

1. 下载OpenWrt CT模板

  • 复制以下命令到PVE终端下载OpenWrt CT模板
1
wget -q -O /var/lib/vz/template/cache/immortalwrt-24.10.0-x86-64-rootfs.tar.gz 'https://github.ixin.top/https://github.com/Thx-Zq/PVE-/releases/download/LXC_OpenWrt/immortalwrt-24.10.0-x86-64-rootfs.tar.gz'

2. 安装OpenWrt容器

  • 复制以下命令到PVE终端安装OpenWrt容器
1
2
3
4
5
6
7
8
9
10
pct create 100 \
local:vztmpl/immortalwrt-24.10.0-x86-64-rootfs.tar.gz \
--rootfs xt:5 \
--ostype unmanaged \
--hostname OpenWrt \
--arch amd64 \
--cores 2 \
--memory 512 \
--swap 0 \
-net0 bridge=vmbr0,name=eth0

解释:
pct create:容器创建命令
100:容器ID,可根据自己情况设定
local:vztmpl/immortalwrt-24.10.0-x86-64-rootfs.tar.gz: 上传/下载到local—CT模板中的OP固件全名
--rootfs:模版为rootfs文件
local-lvm:1 :模板安装后磁盘镜像所在(部分小伙伴可能只有1个local没有local-lvm,注意用local),冒号后数字代表分配磁盘大小(单位G)按需设置,1为1G,2为2G
--ostype unmanaged:操作系统类型,这里没有填写指定的操作系统(不会影响)
--hostname Openwrt-LXC:主机名(容器名称)可自定义。
--arch amd64:设置为64位
--cores 1:分配给容器的核心数,1:1核,2:2核等等(按需设置)
--memory 512:分配给容器最大的内存数量(单位M)(按需设置)
--swap 0:交换分区设置为0(按需设置)
-net0 bridge=vmbr0,name=eth0:网卡,上桥接PVE默认虚拟网桥vmbr0,名称eth0。必须,否则op无法联网。

3. 编辑 nano /etc/pve/lxc/100.conf

  • 添加以下特权
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
32
33
34
35
36
37
38
39
lxc.include: /usr/share/lxc/config/openwrt.common.conf
lxc.net.0.flags: up
lxc.net.0.type: veth
lxc.net.0.link: vmbr0
lxc.net.0.name: eth0
lxc.net.0.hwaddr: aa:aa:aa:aa:aa:aa
lxc.net.1.flags: up
lxc.net.1.type: phys
lxc.net.1.link: enp4s0
lxc.net.1.name: eth1
lxc.net.2.flags: up
lxc.net.2.type: phys
lxc.net.2.link: enp5s0
lxc.net.2.name: eth2
lxc.net.3.flags: up
lxc.net.3.type: phys
lxc.net.3.link: enp6s0
lxc.net.3.name: eth3
lxc.net.4.flags: up
lxc.net.4.type: phys
lxc.net.4.link: enp7s0
lxc.net.4.name: eth4
lxc.net.5.flags: up
lxc.net.5.type: phys
lxc.net.5.link: enp8s0
lxc.net.5.name: wan
lxc.apparmor.profile: unconfined
lxc.apparmor.allow_nesting: 1
lxc.cgroup.devices.allow: a
lxc.cgroup2.devices.allow: a
lxc.cap.drop:
lxc.mount.entry: /dev/ppp dev/ppp none bind,create=file
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
lxc.mount.entry: tmp tmp tmpfs rw,nodev,relatime,mode=1777 0 0
lxc.mount.auto: cgroup:rw
lxc.mount.auto: proc:rw
lxc.mount.auto: sys:rw
lxc.autodev: 1

解释:

lxc.net.0.flags: up #别动
lxc.net.0.type: veth #虚拟口“veth”,直通口“phys”
lxc.net.0.link: vmbr0 #该处为虚拟口的名称,直通的填写主机显示网口的名称(这是我的主机管理网口,一定不要直通,但是帅小伙都会搞直通,然后帅帅的问)。
lxc.net.0.name: eth0 #虚拟机中显示网口的名称。
lxc.net.0.hwaddr: aa:aa:aa:aa:aa:aa #虚拟mac地址,不填写会自动生成。

以上我有6个网口,如果不是6网口的按需添加,添加了虚拟网口的要在虚拟机中把网口移除掉

二. 初始化

1. 启动OP-LXC容器

  1. 编辑 vi /etc/config/network
  2. 键盘按 i 进入编辑模式修改IP
  3. 修改完IP后键盘按 ESC 退出编辑模式——英文冒号 :wq 回车保存退出
  4. service network restart 重启网络服务

2. 浏览器中输入OP-LXC的IP 登录WebUI

  • 初始化网络接口
  1. 网关(主路由)
  2. DNS(主/备2个较好)
  3. HDCP(开启此处DHCP)
  4. IPv6(按需开关,如有IPv4公网地区,可以完全关闭v6避免不必要的麻烦)

3. 开启IPv6

  1. wan6 接口设置

OP-wan6.png

  1. lan 接口配置

op-lan-1.png

op-lan-2.png

op-lan-3.png

  1. wan 接口配置
  • 上面两步完成后不配置这一步也可以获取IPv6

op-wan-1.png

op-wan-2.png

三. 访问光猫后台

添加新接口

名称:onu

协议:静态地址

设备:wan

op-onu-1.png

op-onu-2.png

假设你的光猫ip后台地址是192.168.1.1,那你onu接口的ipv4地址要设置成和你光猫后台ip同网段,不能设置成192.168.1.1,应该设置成192.168.1.2-254都可以设置,打开浏览器输入你的光猫后台IP就可以访问了

四. 安装插件

进入 系统-软件包-更新列表

  1. ttyd 终端
  2. luci-app-advanced-reboot 高级重启
  3. luci-app-filemanager 文件管理器
  • 安装iStore商店(ARM64 & x86-64通用)
1
2
3
4
5
opkg update || exit 1
cd /tmp
wget https://github.ixin.top/https://github.com/linkease/openwrt-app-actions/raw/main/applications/luci-app-systools/root/usr/share/systools/istore-reinstall.run
chmod 755 istore-reinstall.run
./istore-reinstall.run
  • 安装网络向导和首页(ARM64 & x86-64通用)
1
is-opkg install luci-i18n-quickstart-zh-cn

五. 终端免密登录

编辑 vi /etc/config/ttyd 文件目录

  • /bin/login 后面加 -f root 变成 ‘/bin/login -f root’

op-zd.png

输入命令 /etc/init.d/ttyd reload 生效

六. PVE添加虚拟桥接

在vmbr0网桥中加入 lo

  • 这样PVE管理口即使没有插网线也有网络

pve-wq.png