Linux iptables startup script

Source: Internet
Author: User


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

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.