{"id":461,"date":"2013-09-20T01:42:57","date_gmt":"2013-09-20T01:42:57","guid":{"rendered":"https:\/\/shan.info\/new\/force-iptables-to-log-messages-to-a-different-log-file\/"},"modified":"2013-09-20T01:42:57","modified_gmt":"2013-09-20T01:42:57","slug":"force-iptables-to-log-messages-to-a-different-log-file","status":"publish","type":"post","link":"https:\/\/shan.info\/new\/force-iptables-to-log-messages-to-a-different-log-file\/","title":{"rendered":"Force iptables to log messages to a different log file"},"content":{"rendered":"<div class=\"headline_area\" style=\"padding: 0px; margin: 0px 0px 2.2em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 12px; line-height: normal;\">\n<h1 class=\"entry-title\" style=\"font-weight: normal; color: #111111; font-size: 2.6em; line-height: 1.308em;\">Force iptables to log messages to a different log file<\/h1>\n<ol style=\"list-style-type: lower-roman;\">\n<li><span class=\"author vcard\" style=\"padding: 0px; margin: 0px; font-style: normal; text-transform: uppercase; letter-spacing: 1px;\"><a class=\"url fn\" style=\"padding: 0px; margin: 0px; color: #888888; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #eeeeee;\" href=\"http:\/\/www.cyberciti.biz\/tips\/about-us\" rel=\"author\">NIXCRAFT<\/a><\/span>&nbsp;on&nbsp;<abbr class=\"published\" style=\"padding: 0px; margin: 0px; line-height: 1em; text-transform: uppercase; letter-spacing: 1px; border-bottom-width: 0px; font-style: normal;\" title=\"2006-10-03\">OCTOBER 3, 2006<\/abbr>&nbsp;\u00b7&nbsp;<span style=\"padding: 0px; margin: 0px; font-style: normal; text-transform: uppercase; letter-spacing: 1px;\"><a style=\"padding: 0px; margin: 0px; color: #888888; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #eeeeee;\" href=\"http:\/\/www.cyberciti.biz\/tips\/force-iptables-to-log-messages-to-a-different-log-file.html#comments\" rel=\"nofollow\">38 COMMENTS<\/a><\/span>\u00b7&nbsp;<span style=\"padding: 0px; margin: 0px; font-style: normal; text-transform: uppercase; letter-spacing: 1px;\">LAST UPDATED&nbsp;<abbr class=\"updated\" style=\"padding: 0px; margin: 0px; line-height: 1em; letter-spacing: 1px; border-bottom-width: 0px;\" title=\"2008-02-23\">FEBRUARY 23, 2008<\/abbr><\/span><\/li>\n<li><span style=\"padding: 0px; margin: 0px; font-style: normal; text-transform: uppercase; letter-spacing: 1px;\"><a style=\"padding: 0px; margin: 0px; color: #888888; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #eeeeee;\" href=\"http:\/\/www.cyberciti.biz\/tips\/category\/iptables\" rel=\"tag\">IPTABLES<\/a>,&nbsp;<a style=\"padding: 0px; margin: 0px; color: #888888; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #eeeeee;\" href=\"http:\/\/www.cyberciti.biz\/tips\/category\/linux\" rel=\"tag\">LINUX<\/a>,&nbsp;<a style=\"padding: 0px; margin: 0px; color: #888888; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #eeeeee;\" href=\"http:\/\/www.cyberciti.biz\/tips\/category\/monitoring\" rel=\"tag\">MONITORING<\/a><\/span><\/li>\n<\/ol>\n<\/div>\n<div class=\"format_text entry-content\" style=\"padding: 0px; margin: 0px; font-size: 1.4em; line-height: 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;\">\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">According to man page:<br style=\"padding: 0px; margin: 0px;\" \/>Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user defined chains.<\/p>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">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.<\/p>\n<h3 style=\"margin-top: 1.833em; margin-bottom: 0.611em; font-weight: normal; font-size: 1.286em; line-height: 1.222em;\">Iptables default log file<\/h3>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">For example, if you type the following command, it will display current iptables log from \/var\/log\/messages file:<br style=\"padding: 0px; margin: 0px;\" \/><code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\"># tail -f \/var\/log\/messages<\/code><br style=\"padding: 0px; margin: 0px;\" \/>Output:<\/p>\n<pre style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; background-color: #eeeeee; border: 1px solid #dddddd; overflow: auto; clear: both; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; line-height: 1.5em;\">Oct  4 00:44:28 debian gconfd (vivek-4435): Resolved address \"xml:readonly:\/etc\/gconf\/gconf.xml.defaults\" to a read-only configuration source at position 2\r\nOct  4 01:14:19 debian kernel: IN=ra0 OUT= MAC=00:17:9a:0a:f6:44:00:08:5c:00:00:01:08:00 SRC=200.142.84.36 DST=192.168.1.2 LEN=60 TOS=0x00 PREC=0x00 TTL=51 ID=18374 DF PROTO=TCP SPT=46040 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0\r\nOct  4 00:13:55 debian kernel: IN=ra0 OUT= MAC=ff:ff:ff:ff:ff:ff:00:18:de:55:0a:56:08:00 SRC=192.168.1.30 DST=192.168.1.255LEN=78 TOS=0x00 PREC=0x00 TTL=128 ID=13461 PROTO=UDP SPT=137 DPT=137 LEN=58<\/pre>\n<h3 style=\"margin-top: 1.833em; margin-bottom: 0.611em; font-weight: normal; font-size: 1.286em; line-height: 1.222em;\">Procedure to log the iptables messages to a different log file<\/h3>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">Open your \/etc\/syslog.conf file:<br style=\"padding: 0px; margin: 0px;\" \/><code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\"># vi \/etc\/syslog.conf<\/code><br style=\"padding: 0px; margin: 0px;\" \/>Append following line<br style=\"padding: 0px; margin: 0px;\" \/><code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\">kern.warning\t \/var\/log\/iptables.log<\/code><br style=\"padding: 0px; margin: 0px;\" \/>Save and close the file.<\/p>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">Restart the syslogd (Debian \/ Ubuntu Linux):<code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\"># \/etc\/init.d\/sysklogd restart<\/code>On the other hand, use following command to restart syslogd under Red Hat\/Cent OS\/Fedora Core Linux:<code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\"># \/etc\/init.d\/syslog restart<\/code><\/p>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">Now make sure you pass the&nbsp;<a style=\"padding: 0px; margin: 0px; text-decoration: underline; color: #2361a1;\" href=\"http:\/\/www.cyberciti.biz\/nixcraft\/vivek\/blogger\/2006\/03\/how-can-i-enable-or-setup-log-message.php\">log-level 4 option with log-prefix<\/a>&nbsp;to iptables. For example:<br style=\"padding: 0px; margin: 0px;\" \/><code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\"># DROP everything and Log it<br style=\"padding: 0px; margin: 0px;\" \/>iptables -A INPUT -j LOG --log-level 4<br style=\"padding: 0px; margin: 0px;\" \/>iptables -A INPUT -j DROP<\/code><\/p>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">For example, drop and log all connections from IP address 64.55.11.2 to your \/var\/log\/iptables.log file:<br style=\"padding: 0px; margin: 0px;\" \/><code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\">iptables -A INPUT -s 64.55.11.2 -m limit --limit 5\/m --limit-burst 7 -j LOG --log-prefix '** HACKERS **'--log-level 4<br style=\"padding: 0px; margin: 0px;\" \/>iptables -A INPUT -s 64.55.11.2 -j DROP<br style=\"padding: 0px; margin: 0px;\" \/><\/code><\/p>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">Where,<\/p>\n<ul style=\"margin-bottom: 1.571em; margin-left: 1.571em; list-style-type: square;\">\n<li style=\"padding: 0px; margin: 0px;\"><strong style=\"padding: 0px; margin: 0px;\">&#8211;log-level 4<\/strong>: Level of logging. The level # 4 is for warning.<\/li>\n<li style=\"padding: 0px; margin: 0px;\"><strong style=\"padding: 0px; margin: 0px;\">&#8211;log-prefix &#8216;*** TEXT ***&#8217;<\/strong>: Prefix log messages with the specified prefix (TEXT); up to 29 letters long, and useful for distinguishing messages in the logs.<\/li>\n<\/ul>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">You can now see all iptables message logged to \/var\/log\/iptables.log file:<br style=\"padding: 0px; margin: 0px;\" \/><code style=\"padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat;\"># tail -f \/var\/log\/iptables.log<\/code><\/p>\n<p style=\"padding: 0px; margin-top: 0px; margin-bottom: 1.571em;\">Updated for accuracy.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Force iptables to log messages to a different log file NIXCRAFT&nbsp;on&nbsp;OCTOBER 3, 2006&nbsp;\u00b7&nbsp;38 COMMENTS\u00b7&nbsp;LAST UPDATED&nbsp;FEBRUARY 23, 2008 IPTABLES,&nbsp;LINUX,&nbsp;MONITORING According to man page:Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-461","post","type-post","status-publish","format-standard","hentry","category-centos-6"],"_links":{"self":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/posts\/461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/comments?post=461"}],"version-history":[{"count":0,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/posts\/461\/revisions"}],"wp:attachment":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/media?parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}