• Welcome to LiuJason's Blog!

Proxmox VE (PVE)使用命令行批量开启虚拟机VM防火墙

Linux笔记 Jason 2 years ago (2022-08-01) 304 Views 0 Comments QR code of this page

直接上代码,首先添加防火墙规则,vmid是1001到1191的VM,这里禁用mail功能

for i in {1..191};
do
	echo '[OPTIONS]

enable: 1
policy_in: ACCEPT

[RULES]

OUT Mail(REJECT) -log nolog' > /etc/pve/firewall/$((i+1000)).fw;
done

启用防火墙(网卡net0)

for i in {1..191};
do
vm_id=$((i+1000))
temp=$(qm config ${vm_id} --current | grep ^net0 | cut -d " " -f 2);
if [ $(echo $temp | grep firewall)  ]; then
   qm set ${vm_id} --net0 $(echo $temp |sed "s/firewall=[^,]*/firewall=1/")
else
    qm set ${vm_id} --net0 $(echo ${temp}",firewall=1")
fi
done

This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/1233.html
Like (1)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址