Classic Iptables shell Script

Source: Internet
Author: User
Tags iptables

PS: This iptables script is good, very practical, according to the actual application changes can be used by themselves. Share it for everyone to reference. Original author Anonymous. The source code is as follows:

#!/bin/shmodprobe ipt_masquerademodprobe ip_conntrack_ftpmodprobe ip_nat_ftpiptables-fiptables-t nat-fiptables- Xiptables-t nat-x########################## #INPUT键 ################################## #iptables-P INPUT Dropiptables-a input-m State--state established,related-j acceptiptables-a input-p tcp-m multiport--dports 110, 80, 25-j acceptiptables-a input-p tcp-s 192.168.0.0/24--dport 139-j accept# allow intranet samba,smtp,pop3, connect iptables-a input-i et H1-p udp-m multiport--dports 53-j accept# allow DNS connection iptables-a input-p tcp--dport 1723-j acceptiptables-a input-p gr E-j accept# allow extranet VPN connection iptables-a input-s 192.186.0.0/24-p tcp-m State--state established,related-j acceptiptables-a Input-i ppp0-p TCP--syn-m connlimit--connlimit-above 15-j drop# in order to prevent too many DOS connections coming in, you can allow up to 15 initial connections, over the discarded iptables-a INPUT -S 192.186.0.0/24-p tcp--syn-m connlimit--connlimit-above 15-j drop# in order to prevent too many DOS connections coming in, then you can allow up to 15 initial connections, more than the discard iptables-a in Put-p icmp-m limit--limit 3/s-j LOG--log-leVel INFO--log-prefix "ICMP packet in:" Iptables-a input-p icmp-j drop# prohibit ICMP traffic-ping not iptables-t nat-a postrouting- o ppp0-s 192.168.0.0/24-j masquerade# Intranet forwarding iptables-n syn-floodiptables-a input-p tcp--syn-j syn-floodiptables-i syn -flood-p tcp-m limit--limit 3/s--limit-burst 6-j returniptables-a syn-flood-j reject# prevent SYN attack light weight #################### # # #FORWARD链 ########################## #iptables-P FORWARD dropiptables-a forward-p tcp-s 192.168.0.0/24-m multiport-- Dports 80,110,21,25,1723-j acceptiptables-a forward-p udp-s 192.168.0.0/24--dport 53-j acceptiptables-a forward-p Gre-s 192.168.0.0/24-j acceptiptables-a forward-p icmp-s 192.168.0.0/24-j accept# allow VPN clients to go VPN network connection extranet Iptables-a FORWA Rd-m State--state established,related-j acceptiptables-i forward-p udp--dport 53-m string--string "Tencent"-M Tim  E--timestart 8:15--timestop--days mon,tue,wed,thu,fri,sat-j drop# Monday to Saturday 8:00-12:30 prohibit QQ communication iptables-i forward-p UDP--dport 53-m StrinG--string "Tencent"-m time--timestart 8:15--timestop 12:30pm--days mon,tue,wed,thu,fri,sat-j drop# Monday to Saturday 8:00-12:30 ban Stop QQ communication iptables-i forward-p UDP--dport 53-m string--string "Tencent"-m time--timestart 13:30--timestop 20:30--days Mon,tue,wed,thu,fri,sat-j dropiptables-i forward-p UDP--dport 53-m string--string "Tencent"-m time--timestart 13: --timestop 20:30--days mon,tue,wed,thu,fri,sat-j drop# Monday to Saturday 13:30-20:30 ban QQ communication iptables-i Forward-s 192.168.0.0/2 4-m string--string "qq.com"-m time--timestart 8:15--timestop 12:30pm--days mon,tue,wed,thu,fri,sat-j drop# Monday to Saturday of 8:  00-12:30 prohibit QQ page iptables-i forward-s 192.168.0.0/24-m string--string "qq.com"-m time--timestart 13:00--timestop 20:30  --days mon,tue,wed,thu,fri,sat-j drop# Monday to Saturday 13:30-20:30 prohibit QQ page iptables-i forward-s 192.168.0.0/24-m string--string "Ay2000.net"-j dropiptables-i forward-d 192.168.0.0/24-m string--string "Broadband Cinema"-j dropiptables-i forward-s 192.168 .0.0/24-m string--strinG "Erotic"-j dropiptables-i forward-p tcp--sport 80-m string--string "ad"-j drop# forbidden ay2000.net, broadband cinema, pornography, ad page connection! But Chinese is not very ideal iptables-a forward-m ipp2p--edk--kazaa--bit-j dropiptables-a forward-p tcp-m ipp2p--ares-j DROPiptable s -A FORWARD -p udp -m ipp2p --kazaa -j DROP#禁止BT连接iptables -A FORWARD -p tcp --syn --dport 80 -m connlimit --connlimit-ab Ove--connlimit-mask 24###################################################################### #sysctl-W Net.ipv4.ip_forward=1 &>/dev/null# Open Forward ################################################################## # # # # #sysctl-W net.ipv4.tcp_syncookies=1 &>/dev/null# Open Syncookie (Lightweight DOS attack prevention) Sysctl-w NET.IPV4.NETFILTER.IP_ conntrack_tcp_timeout_established=3800 &>/dev/null# Set default TCP connection Dementia duration is 3,800 seconds (this option can significantly reduce the number of connections) Sysctl-w Net.ipv4.ip_ conntrack_max=300000 &>/dev/null# settings Support maximum connection tree to 30W (this is based on your memory and iptables version, each connection requires more than 300 bytes) ############## ######################################################## #iptables-I. InPut-s 192.168.0.50-j acceptiptables-i forward-s 192.168.0.50-j accept#192.168.0.50 is my machine, all released! ########################### #完 #########################################

  

 

Classic Iptables shell Script

Related Article

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.