Linux under the firewall iptables learning notes

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.