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

直接上代码,首先添加防火墙规则,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
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy