Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. iptables-save > iptables-backup.rule # 备份
  4.  
  5. port_list=(
  6. 6379
  7. )
  8.  
  9. ip_list=(
  10. 127.0.0.1
  11. )
  12.  
  13. for port in ${port_list[@]}
  14. do
  15. echo -e "\n"
  16. n1=$(iptables -L -n --line-number | grep ${port} | wc -l)
  17. echo "iptables port: $port before: $n1"
  18. for ip in ${ip_list[@]}
  19. do
  20. res=$(iptables -L -n --line-number | grep ${port} | grep ${ip} | wc -l)
  21. echo "$ip:$port:$res"
  22. # 检查下没有设置才设置
  23. if [ $res == 0 ]
  24. then
  25. iptables -I INPUT -p tcp --dport ${port} -s ${ip} -j ACCEPT
  26. fi
  27. done
  28. n2=$(iptables -L -n --line-number | grep ${port} | wc -l)
  29. echo "iptables port: $port after: $n2"
  30. done
  31.  
  32. echo -e "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement