1. 升级系统软件包
$ apt-get update
$ apt-get dist-upgrade
2. 安装 ifupdown2
使用 ifupdown2 网络管理软件包,还可以实时重新加载网络配置,而无需重新启动。
$ apt install ifupdown2
3. 配置物理网卡
使用 PVE 的 WEB 管理界面,设置物理网卡的配置。
注意:一定要分配一个静态的IP地址,否则无法正常登录 PVE
节点 > 系统 > 网络:
- address:192.168.10.66/24
- gateway:192.168.10.1
保存后应用配置
4. 配置虚拟网卡
4.1 修改虚拟网卡配置
使用 PVE 提供管理界面进行配置。 删除 vmbr0 设备的所有配置内容。
编辑 /etc/network/interfaces
$ nano /etc/network/interfaces
加入
source /etc/network/interfaces.d/*
# 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!
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
auto enp1s0
iface enp1s0 inet static
address 192.168.10.66/24
gateway 192.168.10.1
iface vmbr0 inet manual
bridge-ports none
bridge-stp off
brideg-fd
4.2 新建虚拟网卡配置
创建新的虚拟网卡配置
注意:给虚拟网卡指定一个新的静态地址,是为下一级网络提供NAT服务
$ nano /etc/network/interfaces.d/vmbr0-nat
配置内容
auto vmbr0
# private sub network
iface vmbr0 inet static
address 192.168.100.1/24
bridge-ports none
bridge-stp off
bridge-fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-down echo 0 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '192.168.100.0/24' -o enp1s0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '192.168.100.0/24' -o enp1s0 -j MASQUERADE
4.3 应用配置
$ ifup -a