iptables는 로그를 생성하지 않습니다

iptables는 로그를 생성하지 않습니다

make_firewall.shiptables 규칙이 포함된 다음 스크립트 가 있습니다 .

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

관련 정보