By default, Iptables log message to a /var/log/messages file. However you can change this location. I will show you how to create a new logfile called /var/log/iptables.log. Changing or using a new file allows you to create better statistics and/or allows you to analyze the attacks.
Procedure to log the iptables messages to a different log file
Open your /etc/syslog.conf file:# vi /etc/syslog.conf
Append following linekern.warning /var/log/iptables.log
Save and close the file.
Restart the syslogd (Debian / Ubuntu Linux):
#
/etc/init.d/sysklogd restart
On the other hand, use following command to restart syslogd under Red Hat/Cent OS/Fedora Core Linux:
# /etc/init.d/syslog restart
Now make sure you pass the log-level 4 option with log-prefix to iptables. For example:
# DROP everything and Log it
iptables -A INPUT -j LOG --log-level 4
iptables -A INPUT -j DROP
For example, drop and log all connections from IP address 1.1.1.1 to your /var/log/iptables.log file:
iptables -A INPUT -s 1.1.1.1 -m limit --limit 5/m --limit-burst 7 -j LOG --log-prefix '** HACKERS **'--log-level 4
iptables -A INPUT -s 1.1.1.1 -j DROP
Where,
- --log-level 4: Level of logging. The level # 4 is for warning.
- --log-prefix '*** TEXT ***': Prefix log messages with the specified prefix (TEXT); up to 29 letters long, and useful for distinguishing messages in the logs.
You can now see all iptables message logged to /var/log/iptables.log file:# tail -f /var/log/iptables.log
Thanks : MG's Note
ไม่มีความคิดเห็น:
แสดงความคิดเห็น