Shell simple iptables script Management

Source: Internet
Author: User
#! /Bin/bashwhile ["1" = "1"] doclearecho "------------------------ menu --------------------" Echo "(1) service iptables restart" Echo "(2) iptables Add "Echo" (3) iptables Delete "Echo" (4) iptables stop "Echo" (5) iptables save (remember to save and view the ACL after the ACL is entered) "Echo" (6) iptables status "Echo" (7) iptables ACL list "Echo" (0) exit "Echo" ------------------------------------------------- "echo-n" Enter you chose [0-7]: "Read numif [$ {num}-lt 0-o $ {num}-GT 7] Then ECHO" this is not between 0-7 "else if [" $ {num} "=" 1 "] Then service iptables restart & else if [" $ {num} "=" 2 "] ############ ######################################## # Then while ["1" = "1"] Do clear echo "------------------------ add ACL ----------------------" Echo "(1) add "Echo" for source IP address access (2) Add "Echo" for server port access (3) add the ACL with ports and services (here we need to add the parameter IP address and port such as 0/0 80) "Echo" (4) custom Add "Echo" (5) return to "Echo" --------------------------------------------------- "echo-n" Enter you chose [0-4]: "Read aclnum if [" $ {aclnum} "=" 1 "] Then read IP iptables-A input-S $ {IP}-p tcp -- dport 22-J accept service iptables save Elif ["$ {aclnum}" = "2"] Then read IP iptables-A input-p tcp -- dport $ {IP}-J accept service iptables save Elif ["$ {aclnum}" = "3"] Then read IP port iptables-A input-p tcp-S $ {IP} -- dport $ {port}-J accept service iptables save Elif ["$ {aclnum}" = "4"] Then read addacl '$ {addacl}' service iptables save else break echo fi-n "do you want to add more: [Y/n]: "Read contine if [" $ {contine} "=" N "-o" $ {contine} "=" N "] Then break fi done ###### ######################################## ######## else if ["$ {num}" = "3"] Then while ["1" = "1"] Do clear echo" --------------------- Delete ACL -------------------- "Echo" (1) delete "Echo" for source IP address (2) Delete "Echo" for port (3) Delete "Echo" for ACL with port and Service (4) custom deletion "Echo" (5) returned to the previous "Echo" ------------------------------------------------- "echo-n" Enter you chose [0-5]: "Read aclnum if [" $ {aclnum} "=" 1 "] Then read IP iptables-D input-S $ {IP}-p tcp -- dport 22-J accept service iptables save Elif ["$ {aclnum}" = "2"] Then read port iptables-D input-p tcp -- dport $ {port}-J accept service iptables save Elif ["$ {aclnum}" = "3"] Then read IP port iptables-D input-p tcp-S $ {IP} -- dport $ {port}-J accept service iptables save Elif ["$ {aclnum}" = "4"] Then read deleteacl '$ {deleteacl}' service iptables save else break fi echo-n "do you want to add more: [Y/n]: "Read contine if [" $ {contine} "=" N "-o" $ {contine} "=" N "] Then break fi done ###### ######################################## #################### else if ["$ {num}" = "4"] Then ECHO-e "'service iptables stop & '" else if ["$ {num}" = "5"] Then ECHO-e "'service iptables Save &'" else if ["$ {num} "=" 6 "] Then ECHO-e" 'service iptables Status & '"else if [" $ {num} "=" 7 "] Then while ["1" = "1"] Do clear echo "----------------------- list ACL --------------------" Echo "(1) view the currently used Rule Set "Echo" (2) view the simple traffic statistics for each policy or rule and chain "Echo" (3) view NAT table "Echo" (4) custom view "Echo" (5) return to previous level "Echo" ------------------------------------------------- "echo-n" Enter you chose [0-5]: "Read aclnum if [" $ {aclnum} "=" 1 "] Then iptables-l Elif [" $ {aclnum} "=" 2 "] Then iptables-l- n-V Elif ["$ {aclnum}" = "3"] Then iptables-l-T Nat Elif ["$ {aclnum}" = "4"] Then read listacl '$ {listacl}' else break fi echo-n: [Y/n]: "Read contine if [" $ {contine} "=" N "-o" $ {contine} "=" N "] Then break fi done ###### ######################################## # else exitfi fi fiecho-n "Do You contine [Y/n]: "Read contineif [" $ {contine} "=" N "-o" $ {contine} "=" N "] Then exitfidone
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.