适用于畅网 N305 双网口主机,PVE 系统中安装 iKuai 路由,构建不依赖外网即可访问的内网环境。支持开发环境内所有虚拟机联网,PVE 自身也加入内网。即使没有外网接入,也能通过内网访问 PVE 管理界面。
✅ 网络目标概述
物理网口
enp5s0
:接入宽带网络(外网)enp4s0
:直通给 iKuai,作为 LAN 接口,同时也是 n305 设备内所有虚拟机的内网出口
PVE 虚拟网桥
vmbr0
:桥接 enp5s0,供 iKuai 虚拟机作为 WAN 使用vmbr1
:桥接 enp4s0,供 PVE 自身及所有虚拟机加入 iKuai 管理的内网
✅ 架构图(字符版)
┌──────────────────────┐
│ 上级路由 / 光猫 │
│ (172.18.18.x) │
└────────┬─────────────┘
│
│ 网线
▼
┌──────────────────────┐
│ N305主机 (PVE) │
│ │
│ ┌──────────────┐ │
│ │ enp5s0 │◄──┘
│ │ ↳ vmbr0 (WAN桥) │
│ └────┬─────────┘
│ │
│ ▼ │
│ ┌──────────────┐ │
│ │ iKuai虚拟机 │ │
│ │ │ │
│ │ ↳ vmbr0 = WAN口 │
│ │ ↳ vmbr1 = LAN口 │
│ └────┬─────────┘
│ │
│ ▼
│ ┌──────────────┐
│ │ vmbr1桥(LAN) │
│ │ 子网: 10.10.18.0/24 │
│ └────┬─────────┘
│ │
┌─────────────┼────┬────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ PVE主机本身 │ │ VM1(Linux) │ │ VM2(Win) │
│ 10.10.18.100 │ │ DHCP分配IP │ │ DHCP分配IP │
└────────────┘ └────────────┘ └────────────┘
│
▼
┌────────────┐
│ enp4s0物理网口│
└────┬───────┘
│
▼
┌────────────┐
│ 外部PC/Laptop│
│ DHCP分配IP │
└────────────┘
✅ /etc/network/interfaces 配置模板(使用静态 IP)
auto lo
iface lo inet loopback
iface enp5s0 inet manual
iface enp4s0 inet manual
auto vmbr0
iface vmbr0 inet dhcp
bridge-ports enp5s0
bridge-stp off
bridge-fd 0
auto vmbr1
iface vmbr1 inet static
address 10.10.10.2
netmask 255.255.255.0
gateway 10.10.10.1
bridge-ports enp4s0
bridge-stp off
bridge-fd 0
✅ 一键配置脚本:net-config.sh
保存为 /root/net-config.sh
,并赋予执行权限:
chmod +x /root/net-config.sh
脚本内容如下:
#!/bin/bash
set -e
if [ -z "$1" ]; then
echo "❌ 用法: $0 <静态IP地址,例如 10.10.10.2>"
exit 1
fi
STATIC_IP="$1"
GATEWAY="$(echo $STATIC_IP | awk -F. '{print $1"."$2"."$3".1"}')"
echo "🔧 正在覆盖 /etc/network/interfaces ..."
cat > /etc/network/interfaces <<EOF
# network interface settings; autogenerated
# Please do NOT modify this file directly, unless you know what
# you're doing.
#
# If you want to manage parts of the network configuration manually,
# please utilize the 'source' or 'source-directory' directives to do
# so.
# PVE will preserve these directives, but will NOT read its network
# configuration from sourced files, so do not attempt to move any of
# the PVE managed interfaces into external files!
auto lo
iface lo inet loopback
auto enp5s0
iface enp5s0 inet manual
auto enp4s0
iface enp4s0 inet manual
allow-hotplug vmbr0
auto vmbr0
iface vmbr0 inet dhcp
bridge-ports enp5s0
bridge-stp off
bridge-fd 0
auto vmbr1
iface vmbr1 inet static
address $STATIC_IP
netmask 255.255.255.0
gateway $GATEWAY
bridge-ports enp4s0
bridge-stp off
bridge-fd 0
source /etc/network/interfaces.d/*
EOF
echo "✅ 新配置已写入 /etc/network/interfaces"
echo "📡 内网 IP: $STATIC_IP"
echo "🌐 网关地址: $GATEWAY"
echo "🔁 正在重载网络配置..."
ifreload -a || {
echo "⚠️ ifreload 失败,尝试重启网络接口..."
ifdown vmbr0 && ifup vmbr0
ifdown vmbr1 && ifup vmbr1
}
echo "🎉 完成!建议 reboot 以确保配置生效"
使用示例:
./net-config.sh 10.10.10.2
✅ vmbr0 单用 / 双用 配置示例
单用(仅供 iKuai 使用):
auto vmbr0
iface vmbr0 inet manual
bridge-ports enp5s0
bridge-stp off
bridge-fd 0
双用(PVE 也从外网 DHCP 获取 IP):
auto vmbr0
iface vmbr0 inet dhcp
bridge-ports enp5s0
bridge-stp off
bridge-fd 0
✅ 操作步骤总结(保姆级)
1. 在 PVE Web 界面创建 vmbr1
- 节点 → 网络 → 创建 Linux Bridge
- 名称:
vmbr1
- 端口:
enp4s0
- IP 留空
- 保存后无需重启
2. 上传并执行网络配置脚本
scp net-config.sh root@<PVE_IP>:/root/
ssh root@<PVE_IP>
chmod +x /root/net-config.sh
./net-config.sh 10.10.10.2
3. 启用网络配置
ifdown vmbr1 && ifup vmbr1
✅ 最终效果
- PVE 管理地址:
10.10.10.2
(或你指定的地址) - 所有虚拟机从 iKuai 获取 DHCP 地址并联网
- 外部设备(如开发笔记本)通过网线接 enp4s0 即可访问 PVE,无需外网
- PVE 即使断网、iKuai 崩溃,仍然可本地访问
🧩 后续建议
- 设置 iKuai 静态分配,确保 PVE 网关地址固定
- 使用内网 DNS 或 hosts 文件简化访问
- 使用交换机扩展 LAN 端口,连接更多开发设备
评论 (0)