First, the opening and closing of the iptables
1. Reboot system effective
[Sun@webserver2 ~]$ sudo chkconfig iptables on
[Sun@webserver2 ~]$ sudo chkconfig iptables off
2. Immediate effect, reboot system failure
[Sun@webserver2 ~]$ sudo service iptables start
[Sun@webserver2 ~]$ sudo service iptables stop shutdown
Second, view iptables configuration
[Sun@webserver2 ~]$ sudo iptables-l-n
Third, open the specified port
Restart Iptables service in effect after each modification
1. Allow local loopback interface (that is, run native access to this computer)
1
[Sun@webserver2 ~]$ sudo iptables-a input-s 127.0.0.1-d 127.0.0.1-j ACCEPT
2. Allow access to 80 ports (Web server common port)
[Sun@webserver2 ~]$ sudo iptables-a input-p tcp--dport 80-j ACCEPT
3. Allow access to 22 ports (SSH port)
[Sun@webserver2 ~]$ sudo iptables-a input-p tcp--dport 22-j ACCEPT
4. Allow access to 3306 ports (MySQL port)
[Sun@webserver2 ~]$ sudo iptables-a input-p tcp--dport 3306-j ACCEPT
5. Allow access to Ports 21 and 20 (FTP server port)
[Sun@webserver2 ~]$ sudo iptables-a input-p tcp--dport 20-j ACCEPT
[Sun@webserver2 ~]$ sudo iptables-a input-p tcp--dport 21-j ACCEPT
6. Allow all native access to the outside
[Sun@webserver2 ~]$ sudo iptables-a output-j ACCEPT
Four, shielding IP
Restart Iptables service in effect after each modification
1. Block single IP
[Sun@webserver2 ~]$ sudo iptables-i input-s 123.45.6.7-j DROP
2. Shielding from 123.0.0.1 to 123.255.255.254 network segment
[Sun@webserver2 ~]$ sudo iptables-i input-s 123.0.0.0/8-j DROP
3. Shielding from 123.1.0.1 to 123.1.255.254 network segment
[Sun@webserver2 ~]$ sudo iptables-i input-s 123.1.0.0/16-j DROP
4. Shielding from 123.1.2.1 to 123.1.2.254 network segment
[Sun@webserver2 ~]$ sudo iptables-i input-s 123.1.2.0/24-j DROP
V. Delete Iptables rules that have been added
Restart Iptables service in effect after each modification
1. Display all iptables in serial number
[Sun@webserver2 ~]$ sudo iptables-l-n--line-numbers
2. Execute Delete serial number 1
1
[Sun@webserver2 ~]$ sudo iptables-d INPUT 1