我试图登录使用iptables传出连接DROP。我想要的是,在记录它们的同时放下并接受连接。我发现-j选项需要DROP/REJECT/ACCEPT/LOG。但我想做一些类似DROP和LOG或ACCEPT和LOG的操作。有没有办法做到这一点?iptables的日志,并在一个规则
回答
例子:
iptables -A INPUT -j LOG --log-prefix "INPUT:DROP:" --log-level 6
iptables -A INPUT -j DROP
登录Exampe:
Feb 19 14:18:06 servername kernel: INPUT:DROP:IN=eth1 OUT= MAC=aa:bb:cc:dd:ee:ff:11:22:33:44:55:66:77:88 SRC=x.x.x.x DST=x.x.x.x LEN=48 TOS=0x00 PREC=0x00 TTL=117 ID=x PROTO=TCP SPT=x DPT=x WINDOW=x RES=0x00 SYN URGP=0
其他选项:
LOG
Turn on kernel logging of matching packets. When this option
is set for a rule, the Linux kernel will print some
information on all matching packets
(like most IP header fields) via the kernel log (where it can
be read with dmesg or syslogd(8)). This is a "non-terminating
target", i.e. rule traversal
continues at the next rule. So if you want to LOG the packets
you refuse, use two separate rules with the same matching
criteria, first using target LOG
then DROP (or REJECT).
--log-level level
Level of logging (numeric or see syslog.conf(5)).
--log-prefix prefix
Prefix log messages with the specified prefix; up to 29
letters long, and useful for distinguishing messages in
the logs.
--log-tcp-sequence
Log TCP sequence numbers. This is a security risk if the
log is readable by users.
--log-tcp-options
Log options from the TCP packet header.
--log-ip-options
Log options from the IP packet header.
--log-uid
Log the userid of the process which generated the packet.
这不回答问题 – carillonator
这不回答问题,自定义链作为@Prevok提到的路要走。 – sberder
小技巧:添加一个空格作为前缀'--log-prefix“INPUT:DROP”'中的最后一个字符,并获得一个日志条目,其中的前缀不会与行的其余部分混淆。 – some
虽然已经一岁多,我碰到这个问题绊了几次上其他谷歌搜索,我相信我可以改善以前的答案为他人的利益。
简短的回答是,你不能在一个线结合了动作,但你可以创建一个链,你想要做什么,然后把它在一个衬垫。
让我们创建一个链来记录和接受:
iptables -N LOG_ACCEPT
而且让我们填充它的规则:
iptables -A LOG_ACCEPT -j LOG --log-prefix "INPUT:ACCEPT:" --log-level 6
iptables -A LOG_ACCEPT -j ACCEPT
现在让我们创建一个链来记录和降:
iptables -N LOG_DROP
让我们来填充它的规则:
iptables -A LOG_DROP -j LOG --log-prefix "INPUT:DROP: " --log-level 6
iptables -A LOG_DROP -j DROP
现在,你可以通过跳跃(-j)到您的自定义链,而不是默认的日志做一个全力以赴的行动/接收/拒收/ DROP:
iptables -A <your_chain_here> <your_conditions_here> -j LOG_ACCEPT
iptables -A <your_chain_here> <your_conditions_here> -j LOG_DROP
为中国GFW:
sudo iptables -I INPUT -s 173.194.0.0/16 -p tcp --tcp-flags RST RST -j DROP
sudo iptables -I INPUT -s 173.194.0.0/16 -p tcp --tcp-flags RST RST -j LOG --log-prefix "drop rst"
sudo iptables -I INPUT -s 64.233.0.0/16 -p tcp --tcp-flags RST RST -j DROP
sudo iptables -I INPUT -s 64.233.0.0/16 -p tcp --tcp-flags RST RST -j LOG --log-prefix "drop rst"
sudo iptables -I INPUT -s 74.125.0.0/16 -p tcp --tcp-flags RST RST -j DROP
sudo iptables -I INPUT -s 74.125.0.0/16 -p tcp --tcp-flags RST RST -j LOG --log-prefix "drop rst"
完全错过了这个问题 – sberder
nflog更好
sudo apt-get -y install ulogd2
ICMP阻止规则例如:
iptables=/sbin/iptables
# Drop ICMP (PING)
$iptables -t mangle -A PREROUTING -p icmp -j NFLOG --nflog-prefix 'ICMP Block'
$iptables -t mangle -A PREROUTING -p icmp -j DROP
而且你可以在日志中搜索前缀 “ICMP块”:
/var/log/ulog/syslogemu.log
在工作中,我需要登录,并在端口993(IMAPS)和995(POP3S)使用iptables模块SSLv3的连接。所以,我结合格特van Dijk的的How to take down SSLv3 in your network using iptables firewall? (POODLE)与Prevok的answer并想出了这个:
iptables -N SSLv3
iptables -A SSLv3 -j LOG --log-prefix "SSLv3 Client Hello detected: "
iptables -A SSLv3 -j DROP
iptables -A INPUT \
-p tcp \! -f -m multiport --dports 993,995 \
-m state --state ESTABLISHED -m u32 --u32 \
"0>>22&[email protected] 12>>26&[email protected] 0 & 0xFFFFFF00=0x16030000 && \
0>>22&[email protected] 12>>26&[email protected] 2 & 0xFF=0x01 && \
0>>22&[email protected] 12>>26&[email protected] 7 & 0xFFFF=0x0300" \
-j SSLv3
说明
要
LOG
和DROP
,创建自定义的链(例如SSLv3
):iptables -N SSLv3 iptables -A SSLv3 -j LOG --log-prefix "SSLv3 Client Hello detected: " iptables -A SSLv3 -j DROP
然后,重定向你想要什么
LOG
和DROP
到链(见-j SSLv3
):iptables -A INPUT \ -p tcp \! -f -m multiport --dports 993,995 \ -m state --state ESTABLISHED -m u32 --u32 \ "0>>22&[email protected] 12>>26&[email protected] 0 & 0xFFFFFF00=0x16030000 && \ 0>>22&[email protected] 12>>26&[email protected] 2 & 0xFF=0x01 && \ 0>>22&[email protected] 12>>26&[email protected] 7 & 0xFFFF=0x0300" \ -j SSLv3
注:心灵的规则的顺序。这些规则不适用于我,直到我把它们放在我的防火墙脚本之上:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- 1. IPTables规则顺序
- 2. iptables规则验证
- 3. iptables规则在启动
- 4. Iptables在一个规则中设置多个多端口
- 5. 如何删除iptables规则
- 6. iptables规则nginx与php-fpm
- 7. iptables规则 - 白名单ips
- 8. iptables输入,输出规则
- 9. 这个iptables规则是什么意思?
- 10. Iptables日志输出清理
- 11. KUBE_SERVICE在iptables中插入拒绝规则
- 12. 如何在iptables中匹配规则?
- 13. 如何在iptables中编辑规则?
- 14. iptables的列表中的移动规则
- 15. 写iptables规则的速度是什么?
- 16. 通过Iptables规则的IDS/IPS功能
- 17. 运行系统命令时,一个iptables规则匹配
- 18. 将iptables规则转换为防火墙cmd规则
- 19. ModSecurity审计日志规则限制
- 20. 如何使用python-iptables编写特定iptables规则
- 21. 为什么iptables不显示规则?
- 22. iptables规则我不能做任何事
- 23. IPTables删除IP和端口规则
- 24. 如何使用xargs删除iptables规则?
- 25. iptables规则只为我工作
- 26. HTTP和HTTPS iptables规则被忽略
- 27. Mod_rewrite:规则集导致奇怪的拆分并在重写日志中追加
- 28. 在stat_binhex R日志规模
- 29. 这个iptables日志条目是关于什么的?
- 30. 规则了一些日子
http://etcinsider.com/blog/2015/05/21/linux-netfilter-aka-iptables -sucks-at-logging/ – poige