直接上代码,首先添加防火墙规则,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