Before we look at the code, we're going to get some commands.
Iptables Open and close
1) effective after reboot
| The code is as follows |
Copy Code |
|
Open: Chkconfig iptables on
Close: Chkconfig iptables off |
2) immediate effect, restart after failure
| The code is as follows |
Copy Code |
Open: Service iptables start
OFF: Service iptables stop |
Scripting code
| The code is as follows |
Copy Code |
|
#!/bin/bash
Case "$" in
Start
#Policy
Iptables-p INPUT DROP
Iptables-p OUTPUT ACCEPT
Iptables-p FORWARD ACCEPT
#Rules
Iptables-a input-i lo-j ACCEPT
Iptables-a Output-o lo-j ACCEPT
Iptables-a input-m State--state invalid-j DROP
Iptables-a input-m State--state established,related-j ACCEPT
Iptables-a output-m State--state established,related-j ACCEPT
Iptables-a input-p icmp-j ACCEPT
#Client
Iptables-a input-i eth0-s 222.222.222.222-j ACCEPT
Iptables-a input-i eth0-s 192.168.1.0/24-j ACCEPT
Iptables-a input-i eth0-s 172.10.0.0/24-j ACCEPT
#HTTP
Iptables-a input-p TCP--dport 80-j ACCEPT
#SSH
Iptables-a input-i eth0-p TCP--dport 62222-j ACCEPT
#MySQL
Iptables-a input-s 172.10.0.0/24-p TCP--dport 3306-j ACCEPT
;;
Stop
Iptables-p INPUT ACCEPT
Iptables-p OUTPUT ACCEPT
Iptables-p FORWARD ACCEPT
Iptables-f
;;
Esac |