In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "Shell implementation of iptables management script method tutorial", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn the "Shell implementation of iptables management script method tutorial" it!
The code is as follows:
#! / bin/bash
While true
Do
Clear
Echo "--menu--"
Echo "(1) service iptables restart"
Echo "(2) iptables add"
Echo "(3) iptables delete"
Echo "(4) iptables stop"
Echo "(5) iptables save (not recommended)"
Echo "(6) iptables status"
Echo "(7) iptables ACL list"
Echo "(0) exit"
Echo "generates 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"]
Do
Clear
Echo "--add ACL--"
Echo "(1) add for source IP release"
Echo "(2) release add for server port"
Echo "(3) add for ACL with ports and services (here you want the parameter IP and port such as 0Unip 080)"
Echo "(4) Custom add"
Echo "(5) return to the next level"
Echo "- -"
Echo-n "enter you chose [0-4]:"
Read aclnum
If ["${aclnum}" = = "1"]
Then
Read ip
Iptables-An INPUT-s ${ip}-p tcp-- dport 22-j ACCEPT
Echo "iptables-An INPUT-s ${ip}-p tcp-- dport 22-j ACCEPT" > > fw.sh
# service iptables save
Elif ["${aclnum}" = = "2"]
Then
Rad ip
Iptables-An INPUT-p tcp-- dport ${IP}-j ACCEPT
Echo "iptables-An INPUT-p tcp-- dport ${IP}-j ACCEPT" > > fw.sh
# service iptables save
Elif ["${aclnum}" = = "3"]
Then
Read ip port
Iptables-An INPUT-p tcp-s ${ip}-- dport ${port}-j ACCEPT
Echo "iptables-An 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 to add: [yOrganization]:"
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 for source ip"
Echo "(2) Delete for Port"
Echo "(3) deletion for ACL with ports and services"
Echo "(4) Custom deletion"
Echo "(5) return to the next 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 to add: [yOrganization]:"
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 rule set currently in use"
Echo "(2) View simple traffic statistics for each policy or rule or chain"
Echo "(3) View NAT Table"
Echo "(4) Custom View"
Echo "(5) return to the next 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 to add: [yOrganization]:"
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 [yzone]:"
Read contine
If ["${contine}" = = "n"-o "${contine}" = = "N"]
Then
Exit
Fi
Done
Thank you for reading, the above is the content of the "Shell implementation of iptables management script method tutorial", after the study of this article, I believe you have a deeper understanding of the Shell implementation of iptables management script method tutorial, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.