How to configure iptables using scripts in CentOS

Source: Internet
Author: User
Today, we will explain the experiment of iptables firewall script configuration on the centos server. through the experiment, we can learn more about the actual use method. see the topology: Lan Gateway: 192.168.1.1eth0192.168.1.110 (intel10, M adaptive Nic, accessible only on a LAN host 192.168.1.11) CentosServer IptablesExperiment on the configuration method of firewall scripts allows you to learn more about the actual use method intuitively. see the topology:


Lan Gateway: 192.168.1.1
Eth0 192.168.1.110 (intel10, M adaptive Nic, accessible only on the LAN-specific host 192.168.1.11)
Eth1 192.168.1.100 (intel Gigabit Nic, only for Internet users, that is, access from 192.168.1.1)
The centos 5.5 host runs vsftpd and sshd services (tcp 2222 is for Internet users, and tcp22 is for LAN 192.168.1.11 only). at the same time, it must be able to implement the yum install function from eth0 on the centos host.
############ Iptables script ##################### #####
IPTABLES =/sbin/iptables
MODPROBE =/sbin/modprobe
##### Flush existing rules and chain policy setting toDROP ########
Echo "[+] Flushing existing iptables rules ...... "
$ IPTABLES-F
$ IPTABLES-F-t nat
$ IPTABLES-X
$ IPTABLES-P INPUT DROP
$ IPTABLES-P OUTPUT DROP
$ IPTABLES-P FORWARD DROP
##### Load ftp connection modules ###
$ MODPROBE ip_conntrack
$ MODPROBE ip_nat_ftp
$ MODPROBE ip_conntrack_ftp
######## INPUT chain ############
Echo "[+] Seting up INPUT chain ...... "
#### State tracking rules
$ IPTABLES-a input-m state -- state INVALID-j LOG -- log-prefix "drop invalid" -- log-ip-options -- log-tcp-options
$ IPTABLES-a input-m state -- state INVALID-j DROP
$ IPTABLES-a input-m state -- state ESTABLISHED, RELATED-jACCEPT
#### Anti-spoofing rules
$ IPTABLES-a input-I eth0-s! 192.168.1.11-j LOG -- log-prefix "spoofed pkt"
$ IPTABLES-a input-I eth0-s! 192.168.1.11-j DROP
$ IPTABLES-a input-I eth1-s! 192.168.1.1-j LOG -- log-prefix "spoofed pkt"
$ IPTABLES-a input-I eth1-s! 192.168.1.1-j DROP
#### ACCPET rules
$ IPTABLES-a input-I eth0-p tcp-s 192.168.1.11-m multiport -- dport 20, 22, 2121 -- syn-m state -- state NEW-j ACCEPT
$ IPTABLES-a input-I eth1-p tcp-s 192.168.1.1-m multiport -- dport 20, 2222, 2121 -- syn-m state -- state NEW-j ACCEPT
$ IPTABLES-a input-p icmp -- icmp-type echo-request-jACCEPT
###### Default input log rule ####
$ IPTABLES-a input-I! Lo-j LOG -- log -- prefix "drop" -- log-ip-options -- log-tcp-options
###### OUTPUT chain #######
Echo "[+] Seting up OUTPUT chain ...... "
#### State tracking rules
$ IPTABLES-a output-m state -- state INVALID-j LOG -- log-prefix "drop invalid" -- log-ip-options -- log-tcp-options
$ IPTABLES-a output-m state -- state INVALID-j DROP

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.