PVE7.2 LXC 安装官方 openwrt 教程,单臂路由,解决了其他设备无法上网的问题【重要更新 - 软路由, x86 系统, openwrt(x86),Router OS 等 - 恩山无线论坛 - Powered by Discuz!
2023-7-5
| 2023-7-5
0  |  0 分钟
type
status
date
Jul 2, 2023 04:20 PM
slug
summary
tags
PVE
路由
category
技术折腾
icon
password
ps:最近发现在 openwrt 重启后 pppoe 拨号出错,今天终于解决了这个问题,修改部分我做了下说明,去掉了钩子,直接挂载,这种 openwrt 重启后拨号也正常了。
一直用的梅林的固件路由,这次终于下定决心花点时间整整软路由了。因为弱电箱太小了,所以里面放不下路由,放了光猫 + 网管交换机,然后划分 vlan,现在打算用软路由替代梅林路由。
pve 版本为 7.2,openwrt 版本为 22.03.3,建议使用 22 版本,使用 21 版本 dhcp 有问题,其他 lan 口设备无法访问外网(看论坛有人说是防火墙不兼容),22 这个版本也有一个问题就是 dnsmasq 无法正常运行,导致 dhcp 无法启动,其他设备无法获取 ip,后面找到国外论坛一个网友的方案解决了。
下图为原来的网络架构图,网件路由准备改为软路由
notion image

本帖隐藏的内容

下面开始安装 openwrt
  • 先下载 openwrt 文件到 CT 模板
    • notion image
  • 然后安装,我的容器 id 是 108,下面的代理中的 108 自行替换为你们自己的,还有下面代码中的 local 一般是 local-lvm,参考自己的 pve 情况修改复制代码~下图也作废
      1. pct create 108 local:vztmpl/openwrt-22.03.3-x86-64-rootfs.tar.gz –rootfs local:8 –ostype unmanaged –hostname OpenWrt –arch amd64 –cores 2 –memory 1024 –swap 0 -net0 bridge=vmbr0,name=eth0
      1. #mkdir /var/lib/vz/snippets(作废)
      1. #cp /usr/share/pve-docs/examples/guest-example-hookscript.pl /var/lib/vz/snippets/hookscript.pl(作废)
      1. #vim /var/lib/vz/snippets/hookscript.pl(作废)
      复制代码~修改 hookscript.pl 内容(作废)~ ~1.         在第 36 行可以找到以下内容
      1. # Second phase ‘post-start’ will be executed after the guest
      1. # successfully started.
        1. print “$vmid started successfully.”;
          1. 修改为
          1. # Second phase ‘post-start’ will be executed after the guest
          1. # successfully started.
          1. system(“lxc-device add -n $vmid /dev/ppp”);
          1. system(“lxc-device add -n $vmid /dev/net/tun”);
          1. print “$vmid started successfully.”;
          notion image
      • 修改容器配置文件复制代码
          1. vim /etc/pve/lxc/108.conf
          _复制代码_添加下面的内容(有修改)

          钩子脚本,用于添加 /dev/ppp 等设备

          1. #hookscript: local:snippets/hookscript.pl(作废)

          openwrt.common.conf 是 PVE 自带的 openwrt 配置文件示例,内含一些基本设置

          1. lxc.include: /usr/share/lxc/config/openwrt.common.conf

          /dev/ppp pppoe 拨号等功能需要用到

          1. lxc.cgroup2.devices.allow: c 108:0 rwm
          1. lxc.mount.entry: /dev/ppp dev/ppp none bind,create=file
          1. lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file

          这里是网卡直通重要的部分(看自己需不需要,不需要的话下面的可以不用添加,其中 enp2s0 是我的,你们需要的自己看其他教程找这个网口名)。

          1. lxc.net.1.type: phys
          1. lxc.net.1.link: enp2s0
          1. lxc.net.1.flags: up
      • 然后启动容器,这个时候启动后 openwrt 的 dnsmasq 无法正常启动,ssh 连接 openwrt 后修改 / etc/init.d/dnsmasq 文件
          1. vim /etc/init.d/dnsmasq
          复制代码
      notion image
      重启 dnsmasq
      1. /etc/init.d/dnsmasq restart
      _复制代码_检测 dnsmasq 是否启动有个简单版本,ssh 到 openwrt 后执行 netstat -nap,看看有没有一个 53 端口的 dnsmasq 在里面,有的话说明 dnsmasq 已经成功运行了,运行了如果其他设备还是无法上网,用其他设备测试下 openwrt 的 53 端口是否可以访问,如果不能访问,在 pve 上给 openwrt 的防火墙上开放下端口
      openwrt 划分 vlan
      先添加直通网口到网桥设备,不需要网口直通或者只有单网口的可以跳过这步
      notion image
      notion image
      notion image
      notion image
      如果需要访问光猫,添加一个接口到光猫的 ip,假如光猫 ip 为 1192.168.1.1
      notion image
      到此基本 openwrt 已经基本添加完成,下图为 openwrt 接口全局图
      notion image
      对于有需要 ipv6 外网访问家里设备的(需要有公网 ipv6),需要在 openwrt 防火墙添加流量规则,下图做个参考
      notion image
      LXC 中的 openwrt 重启一次一般是 10s 左右,尽量不要关闭 openwrt,特别是只有一个 wan 口的情况下,关闭 openwrt 可能导致无法连接 pve 管理了,如果有 wifi 的话可以参考其他文章把 wifi 做个接口(类似上图中的 lan 口),万一出了问题,通过 wifi 连接可以管理 pve。 参考:https://www.right.com.cn/forum/thread-8252802-1-1.html
      notion image
      zjxxs391
      x2009again 发表于 2023-2-20 21:33
      那你应该和我的问题一样啊,用我的方法试试,我也是可以拨号,但是其他设备无法联网,只有 op 可以上网
      按你的操作了一下,测试了一下 op 重启拨号以后有网了,再测了下 3322 的 ddns 也解析成功,其他的明天再搞了
      我用到的功能不多,梯子和 udpxy 也能成功就可以使用了
      notion image
      x2009again
      tmdhx 发表于 2023-2-20 14:08
      我之前也是一直没成功
      试试我的方法,一个简单测试 dnsmasq 是否运行的方法就是测试 openwrt 的 53 端口是否通了,如果端口没通在 ssh 到 openwrt 看看服务是不是启动了,命令 netstat -nap 看有没有 dnsmasq 服务,如果没有的话肯定是 dnsmasq 故障了
      notion image
      x2009again _ 本帖最后由 x2009again 于 2023-2-20 08:39 编辑_
      maojindao 发表于 2023-2-20 00:34
      请问这样组网的原因是各房间网线的起点都在弱电箱是吗?
      是啊,一般房子都是设置布置的,不过我改了下交换机的 vlan,把软路由放在一个房间了,客厅的旧路由做了 ap 使用,软路由直通的一个口子做了 lan 口连接路由 ap。
      notion image
      maojindao 请问这样组网的原因是各房间网线的起点都在弱电箱是吗?
      notion image
      tmdhx 我之前也是一直没成功
      notion image
      隨風ぱ奔跑 看看解决方法
      notion image
      jiang99jp 新人学习中。。。。。。
      notion image
      懒懒猪 来看看是怎么设置的
      notion image
      coniccc 看看解决方法
      notion image
      hehe11 PVE7.2 LXC 安装官方官方 openwrt 教程,单臂路由,
      notion image
      zjxxs391 现在用 lxc 只能用 pve7.2 吗?我用 pve7.3 现在能正常拨号,就是内部网络连不上
      notion image
      x2009again
      zjxxs391 发表于 2023-2-20 21:27
      现在用 lxc 只能用 pve7.2 吗?我用 pve7.3 现在能正常拨号,就是内部网络连不上
      那你应该和我的问题一样啊,用我的方法试试,我也是可以拨号,但是其他设备无法联网,只有 op 可以上网
      notion image
      xinSHIkkk kkkkk 信息
      notion image
      sunvool 看看什么解决办法 > 本文由简悦 SimpRead 转码
      目录