1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
需要写两个文件
stop_iptables.sh
stop_iptables_login.exp
前提,是安装了expect
yum install expect
代码如下
1.stop_iptables.sh
list 放要关闭的机器ip,是个数组,也可从文件读取 list=cat ·ip.txt
#!/bin/bash
list="192.168.69.69 192.168.69.68"
passwd="123"
for i in $list
do
expect /home/cloud/tool/stop_iptables_login.exp $i $passwd
done
·
2.stop_iptables_login.exp
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 10
spawn ssh root@$ipaddress
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
send "service iptables stop\r"
expect eof
expect{ ..}中可以有多个
使用 expect 关闭集群 可以,但是这个不能用,问题啊