Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- iptables-save > iptables-backup.rule # 备份
- port_list=(
- 6379
- )
- ip_list=(
- 127.0.0.1
- )
- for port in ${port_list[@]}
- do
- echo -e "\n"
- n1=$(iptables -L -n --line-number | grep ${port} | wc -l)
- echo "iptables port: $port before: $n1"
- for ip in ${ip_list[@]}
- do
- res=$(iptables -L -n --line-number | grep ${port} | grep ${ip} | wc -l)
- echo "$ip:$port:$res"
- # 检查下没有设置才设置
- if [ $res == 0 ]
- then
- iptables -I INPUT -p tcp --dport ${port} -s ${ip} -j ACCEPT
- fi
- done
- n2=$(iptables -L -n --line-number | grep ${port} | wc -l)
- echo "iptables port: $port after: $n2"
- done
- echo -e "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement