iptables log 屏蔽指定ip,不记录在日志


你可以使用 `iptables` 的 `LOG` 选项,并结合 `!` 符号(表示“不匹配”)来实现除了指定IP之外的其他所有IP的数据包记录到日志。下面是一个例子: ```bash # 先确保清除与本次设置相同规则,避免重复记录日志 iptables -D INPUT -j LOG --log-prefix "MYLOG: " iptables -I INPUT -j LOG --log-prefix "MYLOG: " # 设置规则,只有当源IP地址不是特定IP时, 才记录日志 iptables -I INPUT -s 111.111.111.111 -j RETURN # 这个规则需要根据你的需求进行更改 iptables -I INPUT -! -s 111.111.111.111 -j LOG --log-prefix "MYLOG: " ``` 上述命令首先清除了之前可能存在的相同位置的规则,然后设置了新的规则,对于INPUT链中的数据包,如果源地址是111.111.111.111,则直接返回(即不做任何操作),否则将其日志信息记录下来。 注意:`iptables` 的具体规则顺序和行为可能取决于你系统上已经存在的防火墙规则,请根据实际情况调整命令。 确保你的系统有权限记录日志,并且已经配置了适当的日志存储位置。通常这些日志会被记录到 `/var/log/kern.log` 或者 `/var/log/messages` 中,具体取决于你的Linux发行版。如果需要查看这些日志,可以使用 `journalctl -k` 或者 `cat /var/log/kern.log | grep MYLOG` 类似的命令。 [2024-08-28 16:04:14 | AI写代码神器 | 365点数解答]
- <!DOCTYPE html> <html> <head> <title>code2</title> <script> let x = 3 console.log(x) console.log(typeof x) x = 'Hello' console.log(x) console.log(typeof x) x = true console.log(x) console.log(typeof x) console.log(2>12) console.log(5 | 1<<1) console.log(5<<1) console.log('A'+123) </script> </head> <body> <p>王荣辉 2025123456</p > </body> </html> (664点数解答 | 2025-06-17 14:30:03)64
- 作为软件工程师,简述域名和 ip 的关系?一个 ip 可以对应多个域名吗?(61点数解答 | 2023-11-09 18:19:12)230
- iptables log 屏蔽指定ip,不记录在日志(365点数解答 | 2024-08-28 16:04:14)133
- iptables log 不记录指定端口的日志(337点数解答 | 2024-08-28 16:05:04)104
- iptables log 不记录指定端口的日志(144点数解答 | 2024-08-28 16:05:19)108
- iptables log 记录符合规则的日志(504点数解答 | 2024-08-28 16:26:23)110
- iptables log 记录不符合规则的日志(318点数解答 | 2024-08-28 16:27:26)97
- iptables log 记录不符合规则的日志(363点数解答 | 2024-08-28 16:27:44)100
- 作为软件工程师,ip 地址有哪些分类?(387点数解答 | 2023-11-09 18:19:21)132
- k8s中使用ingressclass指定nginx ip(349点数解答 | 2024-01-05 16:09:21)171
- eureka.instance.ip-address配置后只会转发到这吗(251点数解答 | 2024-07-11 10:08:51)143
- eureka.instance.ip-address配置后只会转发到配置的ip吗(111点数解答 | 2024-07-11 10:09:42)150