How to log all incoming packets

僤鯓⒐⒋嵵緔 提交于 2019-12-06 04:27:23

You need the logging rule to be at the very beginning of your rules.

# iptables -I INPUT 1 -m limit --limit 5/m -j LOG --log-prefix="iptables: dropped packets" --log-level 4

  • -I INPUT 1 : This means append the rule to the INPUT chain at 1st place just before anything else.

  • -m limit : This tells that we wish to use the limit matching module. Using this we can limit the logging using –limit option.

  • --limit 5/m : Here comes the limit option we just talked about. This means we want to limit the maximum average matching rate for logging to 5 per minute. You can also specify 5/second, 40/minute, 1/hour, 3/day like that according to your environment and needs.

  • -j LOG : This tells iptables to jump to LOG i.e write to the log file.

  • -–log-prefix "iptables: dropped packets" : You can specify any log prefix, which will be appended to the log messages that will be written to the /var/log/messages file

  • -–log-level 4 : syslog level 4 stands for warning. You can use number from the range 0 through 7. 0 being the highest for emergency and 7 being the lowest for debug.

src

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!