大网数据广告活动
服务器运维问答

linux : monit : iptables

· 52CE 我爱测

Under linux, at least centos and I think also debian, there is a "iptables" listed in the daemons. But it is really a script to load and save them, it doesn' start a process, neither write a pidfile. How can I check iptables up a…

问题原文

原帖链接 · Massimo · CC BY-SA 4.0

Under linux, at least centos and I think also debian, there is a "iptables" listed in the daemons. But it is really a script to load and save them, it doesn' start a process, neither write a pidfile.

How can I check iptables up and running with monit ?

已采纳解答

原帖链接 · kenlukas · CC BY-SA 4.0

For CentOS 6 and earlier you're correct about it using iptables. CentOS 7 uses firewalld.

To monitor either using Monit you can use PROGRAM-STATUS-TEST. There are several methods to ascertain the status of iptables.

One method to get the status of iptables in CentOS 6 is to use

$ sudo /etc/init.d/iptables status

If iptables is not running you'll get the following response:

$ sudo /etc/init.d/iptables status
iptables: Firewall is not running.

If iptables is running it will look similar to this:

$ sudo /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Write a script to check the status and grep for Firewall is not running and provide an return code for the script then use monit to run the script.

I didn't test it but it would look something like this:

check program iptables with path "/etc/init.d/iptables status"
    if status != 0 then alert

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-08-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。