![iptables不生成日志](https://linux22.com/image/90565/iptables%E4%B8%8D%E7%94%9F%E6%88%90%E6%97%A5%E5%BF%97.png)
我有这个make_firewall.sh
带有 iptables 规则的脚本:
iptables -F
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -j LOG --log-level info --log-prefix='[netfilter] '
iptables -A INPUT -p tcp -j LOG --log-prefix='[netfilter] '
iptables -A INPUT -p tcp -j DROP
我有这个/etc/rsyslog.d/my_iptables.conf
:
:msg,contains,"[netfilter] " /var/log/iptables.log
还有这个/etc/rsyslog.conf
:
# /etc/rsyslog.conf Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#################
#### MODULES ####
#################
$ModLoad imuxsock # provides support for local system logging
#$ModLoad imklog # provides kernel logging support
#$ModLoad immark # provides --MARK-- message capability
# provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
###############
#### RULES ####
###############
#
# First some standard log files. Log by facility.
#
auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
cron.* -/var/log/cron.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
lpr.* -/var/log/lpr.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
#
# Logging for the mail system. Split it up so that
# it is easy to write scripts to parse these files.
#
mail.info -/var/log/mail.info
mail.warn -/var/log/mail.warn
mail.err -/var/log/mail.err
#
# Logging for INN news system.
#
news.crit -/var/log/news/news.crit
news.err -/var/log/news/news.err
news.notice -/var/log/news/news.notice
#
# Some "catch-all" log files.
#
*.=debug;\
auth,authpriv.none;\
news.none;mail.none -/var/log/debug
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail,news.none -/var/log/messages
#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*
#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
#daemon,mail.*;\
# news.=crit;news.=err;news.=notice;\
# *.=debug;*.=info;\
# *.=notice;*.=warn /dev/tty8
# The named pipe /dev/xconsole is for the `xconsole' utility. To use it,
# you must invoke `xconsole' with the `-file' option:
#
# $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
# busy site..
#
daemon.*;mail.*;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole
该文件夹的内容/var/log
是(我检查了该文件夹上的所有文件,但我没有从 iptables 中找到任何内容):
-rw-r--r-- 1 root root 1593 Jul 1 17:09 alternatives.log
drwxr-x--- 2 root adm 4096 Jul 2 10:13 apache2
drwxr-xr-x 2 root root 4096 Jun 20 16:49 apt
-rw-r----- 1 root adm 4490518 Jul 14 22:58 auth.log
-rw------- 1 root utmp 495361 Jul 14 19:44 btmp
-rw-r----- 1 root adm 180921 Jul 14 20:06 daemon.log
-rw-r----- 1 root adm 775 Jun 20 16:59 debug
-rw-r----- 1 root adm 1 Nov 9 2015 dmesg
-rw-r--r-- 1 root root 132769 Jul 14 20:04 dpkg.log
drwxr-s--- 2 Debian-exim adm 4096 Jul 1 17:09 exim4
-rw-r----- 1 root adm 4363 Jul 14 19:43 fail2ban.log
-rw-r--r-- 1 root root 3424 Jul 1 17:09 faillog
drwxr-xr-x 2 root root 4096 Nov 9 2015 fsck
-rw-rw-r-- 1 root utmp 31244 Jul 14 19:44 lastlog
-rw-r----- 1 root adm 3748 Jul 14 20:06 messages
drwxr-s--- 2 mysql adm 4096 Jun 20 17:03 mysql
-rw-r----- 1 mysql adm 0 Jun 20 17:03 mysql.err
-rw-r----- 1 mysql adm 0 Jun 20 17:03 mysql.log
-rw-r----- 1 root adm 2628602 Jul 14 22:58 syslog
-rw-rw-r-- 1 root utmp 40704 Jul 14 19:44 wtmp
我正在使用:Debian 8 (jessie) 和 iptables v1.4.21
我的问题是:为什么 iptables 不生成任何日志?
谢谢你的帮助!
答案1
我发现rsyslog
最初不会创建自定义日志文件,所以我自己做。
注意:权限一如既往地重要! - 确保 rsyslog 具有写入新日志文件的权限,尝试类似的操作
print_status "Give Iptables its own log file - instead of /var/log/syslog"
sudo touch /var/log/iptables.log
# assign appropriate ownership to your setup
sudo chown -v root:adm /var/log/iptables.log
sudo chmod -v 660 /var/log/iptables.log
那么显然你需要重新启动rsyslog
才能使更改生效
sudo service rsyslog restart
或者您在发行版上使用的任何命令,可能吗?
sudo /etc/init.d/rsyslog restart