iptables:阻止端口但不记录所有端口

时间:2014-09-25 17:43:26

标签: logging redhat iptables

我在iptables中阻止了所有端口,除了那些我特别想要打开的端口。但是,在我的iptables.log文件中,我有几十个使用端口137,138,139的请求,因为我们的公司网络一直认为我们的盒子可能是一个Windows框。不幸的是,我无法阻止这种情况发生,因此下一个选择是打开端口,或阻止写入日志。

是否可以阻止为特定端口编写iptables.log,但是仍然记录所有其他阻塞端口?或者我是否需要完全禁用iptables.log?

这是在我的/etc/rsyslog.conf文件中

:msg, startswith, "iptables: " -/var/log/iptables.log
& ~
:msg, regex, "^\[ *[0-9]*\.[0-9]*\] iptables: " -/var/log/iptables.log
& ~

RedHat 6.5

输出:

Chain INPUT (policy DROP 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1       98  6744 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
2      385 51303 ACCEPT     udp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           udp spt:53
3     2102  166K ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22 state NEW,ESTABLISHED
4        0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp spt:22 state ESTABLISHED
5      119 18187 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp spt:80 state ESTABLISHED
6        0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp spt:443 state ESTABLISHED
7        0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:3306 state NEW,ESTABLISHED
8        0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp spt:3306 state ESTABLISHED
9       70  3104 ACCEPT     tcp  --  eth0   *       10./16        0.0.0.0/0           multiport dports 1556,10082,10102,13720,13724,13782 state NEW,ESTABLISHED
10       0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           multiport sports 1556,10082,10102,13720,13724,13782 state ESTABLISHED
11     115 18624 LOGGING    all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy DROP 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy DROP 887 packets, 53828 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1       98  6744 ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0
2      418 36439 ACCEPT     udp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           udp dpt:53
3     1801  230K ACCEPT     tcp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           tcp spt:22 state ESTABLISHED
4        0     0 ACCEPT     tcp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           tcp dpt:22 state NEW,ESTABLISHED
5      193 21974 ACCEPT     tcp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           tcp dpt:80 state NEW,ESTABLISHED
6        0     0 ACCEPT     tcp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           tcp dpt:443 state NEW,ESTABLISHED
7        0     0 ACCEPT     tcp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           tcp spt:3306 state ESTABLISHED
8        0     0 ACCEPT     tcp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           tcp dpt:3306 state NEW,ESTABLISHED
9       50  4570 ACCEPT     tcp  --  *      eth0    0.0.0.0/0            0.0.0.0/0           multiport sports 1556,10082,10102,13720,13724,13782 state ESTABLISHED
10       0     0 ACCEPT     tcp  --  *      eth0    10./16        0.0.0.0/0           multiport dports 1556,10082,10102,13720,13724,13782 state NEW,ESTABLISHED

Chain LOGGING (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1       94 16986 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 5/min burst 5 LOG flags 0 level 7 prefix `iptables: '
2      115 18624 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0

1 个答案:

答案 0 :(得分:0)

添加以下规则:

sudo iptables -I INPUT 11 -p udp -i eth0 --dport 139 -j DROP
sudo iptables -I INPUT 11 -p udp -i eth0 --dport 138 -j DROP
sudo iptables -I INPUT 11 -p udp -i eth0 --dport 137 -j DROP

这些将导致iptables在达到日志记录规则之前删除指定的数据包。特别是,它在DROP表的INPUT链中将filter操作添加为操作编号11(当前编号为11的日志记录操作之前)。

请注意,您可能需要重新启动iptables,如下所示:

sudo service iptables restart