每天 Shaarli

一天内的所有链接,汇聚在一个页面上。

January 20, 2026

Note: PVE安装OpenWRT的方法

PVE安装OpenWRT的方法

安装PVE虚拟机

下载PVE镜像

https://www.proxmox.com/en/downloads/proxmox-virtual-environment/iso

下载镜像烧录软件

https://etcher.balena.io/#download-etcher

准备一个U盘,并把PVE镜像烧录到U盘

安装PVE虚拟机

※ 把U盘插入计算机(插在后面,别插在HUB)

※ 硬盘磁盘格式化成xfs类型的文件系统

※ 按提示完成安装

进入PVE管理界面

https://YOUR_IP:8006/

安装OpenWRT

下载OpenWRT镜像

https://github.com/firker/openwrt-Exclusive/releases

上传OpenWRT镜像到PVE的ISO镜像

记下上传时镜像的target路径,比如:
/var/lib/vz/template/iso/openwrt-buddha-v2_2024_-x86-64-generic-squashfs-uefi.img

创建一个虚拟网卡

在PVE管理界面的 “节点”→“系统”→“网络”中,点击“创建”按钮,创建一个“Linux Bridge”,并给它一个名字,比如“vmbr1”。

创建一个虚拟机,不需要CD-ROM,其他默认。(假设ID为9000)

导入OpenWRT的镜像成为硬盘,并删除原来的硬盘。

qm importdisk 9000 /var/lib/vz/template/iso/openwrt-buddha-v2_2024_-x86-64-generic-squashfs-uefi.img local-lvm

开机,并配置网络

检查vi /etc/config/network,看看lan和wan是否正确分配给了vmbr1和vmbr0,否则改过来。

重启网络,这时你应该可以看到WAN口IP

/etc/init.d/network restart

ip a
udhcpc -i eth0
ip a show eth0
ip r

关闭OpenWRT系统防火墙

/etc/init.d/firewall stop
/etc/init.d/firewall disable
/etc/init.d/firewall status

关闭后你访问管理页面,没有密码

OpenWrt LuCI 默认是:

http://172.16.101.160/

配置好OpenWrt网络转发,比如

“系统”→“管理权”→“SSH 访问”,指定“接口”的内外网访问。

“网络”→“防火墙”→“端口转发”,映射“OpenWRT管理页面”和“OpenWRT的SSH”。

最后记得 “保存并应用”。恢复防火墙,否则转发规则不会生效。

/etc/init.d/firewall enable
/etc/init.d/firewall start

指定给 某个IP/任何人 访问管理页面

  1. 放行 WAN 口的 HTTP 80(仅某个IP)
uci add firewall rule
uci set firewall.@rule[-1].name='Allow-LuCI-HTTP-from-myPC'
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].proto='tcp'
uci set firewall.@rule[-1].dest_port='80'
uci set firewall.@rule[-1].src_ip='YOUR_IP'
uci set firewall.@rule[-1].target='ACCEPT'
  1. 放行 WAN 口的 HTTPS 443(仅某个IP)

    uci add firewall rule
    uci set firewall.@rule[-1].name='Allow-LuCI-HTTPS-from-myPC'
    uci set firewall.@rule[-1].src='wan'
    uci set firewall.@rule[-1].proto='tcp'
    uci set firewall.@rule[-1].dest_port='443'
    uci set firewall.@rule[-1].src_ip='YOUR_IP'
    uci set firewall.@rule[-1].target='ACCEPT'
  2. 放行 WAN 口的 SSH 22(仅某个IP)

    uci add firewall rule
    uci set firewall.@rule[-1].name='Allow-LuCI-HTTPS-from-myPC'
    uci set firewall.@rule[-1].src='wan'
    uci set firewall.@rule[-1].proto='tcp'
    uci set firewall.@rule[-1].dest_port='22'
    uci set firewall.@rule[-1].src_ip='YOUR_IP'
    uci set firewall.@rule[-1].target='ACCEPT'
  3. 放行 WAN 口指定IP(所有人)

uci add firewall rule
uci set firewall.@rule[-1].name='Allow-LuCI-HTTP-WAN'
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].proto='tcp'
uci set firewall.@rule[-1].dest_port='80'
uci set firewall.@rule[-1].target='ACCEPT'

uci add firewall rule
uci set firewall.@rule[-1].name='Allow-LuCI-HTTPS-WAN'
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].proto='tcp'
uci set firewall.@rule[-1].dest_port='443'
uci set firewall.@rule[-1].target='ACCEPT'

添加完成后,重启防火墙:

uci commit firewall
/etc/init.d/firewall restart

检查是否已生效(可选)

uci show firewall | grep LuCI

规则怎么删除?

在 OpenWrt shell 执行:

uci show firewall | grep Allow-LuCI

你会看到类似输出(举例):

firewall.@rule[7].name='Allow-LuCI-HTTP-from-ZJF'
firewall.@rule[8].name='Allow-LuCI-HTTPS-from-ZJF'

这里的 [7]、[8] 就是规则编号。

按编号删除规则:

uci delete firewall.@rule[7]
uci delete firewall.@rule[8]

保存并应用

uci commit firewall
/etc/init.d/firewall restart

规则都在这里:

vi /etc/config/firewall

扩大OpenWRT的镜像的磁盘大小(不会破坏已有内容)(可选)

qemu-img info /var/lib/vz/template/iso/openwrt-buddha-v2_2024_-x86-64-generic-squashfs-uefi.img
qemu-img resize /var/lib/vz/template/iso/openwrt-buddha-v2_2024_-x86-64-generic-squashfs-uefi.img 2G

最后想“容量真的能用上”,通常还需要在 OpenWrt 里做:

检查当前分区布局

进入 OpenWrt 的 shell,使用 fdisk 或 lsblk 来查看当前分区表。

fdisk -l
lsblk -f
blkid

/dev/sda2 是 squashfs,这是根文件系统,它是只读的。

/dev/loop0 是 f2fs,这是一个可写文件系统,通常作为 overlay 文件系统使用,挂载在 /tmp/extroot/overlay 和 /overlay 上。

扩展 f2fs 文件系统

安装 f2fs-tools(如果没有安装的话)

opkg update
opkg install f2fs-tools

然后,使用 resize.f2fs 来扩展文件系统:

resize.f2fs /dev/loop0

扩展后,使用 df -hlsblk -f 命令确认新的空间已经被成功识别并且分配给了 /overlay