[ShellScript] Script hỗ trợ tính tổng rule iptables đang hoạt động trên Linux

Shell script Linux – “iptables-rules-count.sh”

Miêu tả

iptables-rules-count.sh‘ là một file shell script giúp ta tính tổng số lượng iptables rule firewall đang hoạt động trên hệ thống Linux.

 
Yêu cầu

– Server Linux OS sử dụng netfilter là core tường lửa, sử dụng công cụ ‘iptables’ để set tương tác với ‘netfilter’ giúp kiểm soát hoạt động của ‘netfilter’ thông qua các iptables rule.
– Git tool được cài trên Linux.
– User chạy script phải có quyền hạn chạy tool ‘iptables’ (thường là user cấp cao như ‘root’).
– User có quyền ghi trên thư mục /tmp/ .

 
Nội dung code

Link github: https://github.com/cuongquach/iptables-rules-count.sh.git
Link cuongquach.com : https://cuongquach.com/download/shellscripts/sys/iptables-rules-count.sh.txt

 
Hướng dẫn cài đặt script

+ Linux – Github

# git clone https://github.com/cuongquach/iptables-rules-count.sh.git iptables-rules-count
# mv iptables-rules-count/iptables-rules-count.sh /usr/bin/iptables-rules-count
# chmod 700 /usr/bin/iptables-rules-count && chown root:root /usr/bin/iptables-rules-count
# which iptables-rules-count
/usr/bin/iptables-rules-count

 
+ Linux – cuongquach.com

# wget --no-check-certificate -O /usr/bin/iptables-rules-count https://cuongquach.com/download/shellscripts/sys/iptables-rules-count.sh.txt
# chmod 700 /usr/bin/iptables-rules-count && chown root:root /usr/bin/iptables-rules-count
# which iptables-rules-count
/usr/bin/iptables-rules-count

 
Ví dụ sử dụng

– Tính tổng số lượng iptables rule đang hoạt động trên Linux.

# iptables-rules-count

++++++++++++++++++++++++++++++++++++++++++++
+ Summary information of iptables firewall +
++++++++++++++++++++++++++++++++++++++++++++

---| Sum of current iptables chains : 27 (chains)
---| Sum of active iptable rules : 161 (rules)


+++++++++++++++++++++++++++++++++++++++
+ Table 'filter' of iptables firewall +
+++++++++++++++++++++++++++++++++++++++

-- Chain INPUT : 44 (rules)
-- Chain FORWARD : 0 (rules)
-- Chain OUTPUT : 49 (rules)
-- Chain ALLOWIN : 9 (rules)
-- Chain ALLOWOUT : 1 (rules)
-- Chain DENYIN : 1 (rules)
-- Chain DENYOUT : 1 (rules)
-- Chain INVALID : 10 (rules)
-- Chain INVDROP : 1 (rules)
-- Chain LOCALINPUT : 2 (rules)
-- Chain LOCALOUTPUT : 2 (rules)
-- Chain LOGDROPIN : 22 (rules)
-- Chain LOGDROPOUT : 4 (rules)
-- Chain acctboth : 15 (rules)
---| Sum of amount CHAINS in table 'filter' : 14 (chains)
---| Sum of amount RULES in table 'filter' : 161 (rules)


++++++++++++++++++++++++++++++++++++
+ Table 'nat' of iptables firewall +
++++++++++++++++++++++++++++++++++++

-- Chain PREROUTING : 0 (rules)
-- Chain POSTROUTING : 0 (rules)
-- Chain OUTPUT : 0 (rules)
---| Sum of amount CHAINS in table 'nat' : 3 (chains)
---| Sum of amount RULES in table 'nat' : 0 (rules)


+++++++++++++++++++++++++++++++++++++++
+ Table 'mangle' of iptables firewall +
+++++++++++++++++++++++++++++++++++++++

-- Chain PREROUTING : 0 (rules)
-- Chain INPUT : 0 (rules)
-- Chain FORWARD : 0 (rules)
-- Chain OUTPUT : 0 (rules)
-- Chain POSTROUTING : 0 (rules)
---| Sum of amount CHAINS in table 'mangle' : 5 (chains)
---| Sum of amount RULES in table 'mangle' : 0 (rules)


++++++++++++++++++++++++++++++++++++
+ Table 'raw' of iptables firewall +
++++++++++++++++++++++++++++++++++++

-- Chain PREROUTING : 0 (rules)
-- Chain OUTPUT : 0 (rules)
---| Sum of amount CHAINS in table 'raw' : 2 (chains)
---| Sum of amount RULES in table 'raw' : 0 (rules)


+++++++++++++++++++++++++++++++++++++++++
+ Table 'security' of iptables firewall +
+++++++++++++++++++++++++++++++++++++++++

-- Chain INPUT : 0 (rules)
-- Chain FORWARD : 0 (rules)
-- Chain OUTPUT : 0 (rules)
---| Sum of amount CHAINS in table 'security' : 3 (chains)
---| Sum of amount RULES in table 'security' : 0 (rules)


 
Tác giả

Tên : Quách Chí Cường
Website : https://cuongquach.com/
Github : https://github.com/cuongquach

Previous article[Zabbix] Hướng dẫn cài đặt và cấu hình Zabbix Agent trên FreeBSD OS
Next article[MySQL] Ba cách để biết thông tin thời gian uptime của dịch vụ MySQL
Bạn đang theo dõi website "https://cuongquach.com/" nơi lưu trữ những kiến thức tổng hợp và chia sẻ cá nhân về Quản Trị Hệ Thống Dịch Vụ & Mạng, được xây dựng lại dưới nền tảng kinh nghiệm của bản thân mình, Quách Chí Cường. Hy vọng bạn sẽ thích nơi này !