Shell implementation of Iptables management script sharing _linux Shell

Source: Internet
Author: User
Tags iptables server port

The previous script is in save mode, now attach the command to a file, so that it can be easily modified two times or something
The script is basically like this, we can change with their situation again ~ add function or something.

Copy Code code as follows:

#!/bin/bash
While True
Todo
Clear
echo "----------------------Menu----------------------"
echo "(1) Service iptables restart"
echo "(2) iptables add"
echo "(3) iptables Delete"
echo "(4) iptables stop"
echo "(5) Iptables Save (this mode is not recommended)"
echo "(6) iptables status"
echo "(7) iptables ACL list"
echo "(0) Exit"
Echo will generate a fw.sh file in the current directory.
echo "-------------------------------------------------"
Echo-n "Enter you chose[0-7]:"
Read num
If [${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"]
Todo
Clear
echo "----------------------add ACL----------------------"
echo "(1) adding" for source IP release
echo "(2) for server port release add"
echo "(3) is added for ACLs with ports and services (here to parameter IP and ports such as 0/0 80)"
echo "(4) custom Add"
echo "(5) return to the previous level"
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
echo "Iptables-a input-s ${ip}-P tcp--dport 22-j ACCEPT" >>fw.sh
# Service Iptables Save
elif ["${aclnum}" = = "2"]
Then
rad IP
Iptables-a input-p tcp--dport ${ip}-j ACCEPT
echo "Iptables-a input-p tcp--dport ${ip}-j ACCEPT" >>fw.sh
# Service Iptables Save
elif ["${aclnum}" = = "3"]
Then
Read IP port
Iptables-a input-p tcp-s ${ip}--dport ${port}-j ACCEPT
echo "Iptables-a input-p tcp-s ${ip}--dport ${port}-j ACCEPT" >>fw.sh
# Service Iptables Save
elif ["${aclnum}" = = "4"]
Then
Read Addacl
' ${addacl} '
Service Iptables Save
Else
Break
Fi
Echo-n "Do you want to continue adding: [y/n]:"
Read Contine
if ["${contine}" = = "n"-o "${contine}" = = "N"]
Then
Break
Fi
Done
#######################################################
Else
if ["${num}" = = "3"]
Then
While ["1" = "1"]
Todo
Clear
echo "---------------------Delete ACL----------------------"
echo "(1) for source IP deletion"
echo "(2) for port deletion"
echo "(3) for ACL deletion with ports and services"
echo "(4) Custom Delete"
echo "(5) return to the previous level"
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
echo "Iptables-d input-s ${ip}-P tcp--dport 22-j ACCEPT" >>fw.sh
# Service Iptables Save
elif ["${aclnum}" = = "2"]
Then
Read Port
iptables-d input-p tcp--dport ${port}-j ACCEPT
echo "iptables-d input-p tcp--dport ${port}-j ACCEPT" >>fw.sh
# Service Iptables Save
elif ["${aclnum}" = = "3"]
Then
Read IP port
iptables-d input-p tcp-s ${ip}--dport ${port}-j ACCEPT
echo "iptables-d input-p tcp-s ${ip}--dport ${port}-j ACCEPT" >>fw.sh
# Service Iptables Save
elif ["${aclnum}" = = "4"]
Then
Read Deleteacl
' ${deleteacl} '
Service Iptables Save
Else
Break
Fi
Echo-n "Do you want to continue adding: [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"]
Todo
Clear
echo "---------------------list ACL----------------------"
Echo (1) View the rule set that is currently in use
echo "(2) View the simple traffic statistics for each policy or per rule, per chain
echo "(3) View NAT table"
echo "(4) Custom View"
echo "(5) return to the 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 "Do you want to continue adding: [y/n]:"
Read Contine
if ["${contine}" = = "n"-o "${contine}" = = "N"]
Then
Break
Fi
Done
################################################
Else
Exit
Fi
Fi
Fi
Fi
Fi
Fi
Fi
Fi
Echo-n "Do you contine [y/n]:"
Read Contine
if ["${contine}" = = "n"-o "${contine}" = = "N"]
Then
Exit
Fi
Done

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.