WebHostGear.com - the hosting resource for professionalshosting tutorials 
hosting howto webhost guide server managementFebruary 09, 2010
server management, apache tutorials, hosting tutorials, cpanel, server security
Home / Hosting Tutorials / Server Security / Changing APF log for TDP/UDP drops

Changing APF log for TDP/UDP drops



Printer Friendly Printer Friendly Send to a friend Send to a friend
By : ramprage Rating : Average Rating : 8.38 From 8 Voter(s)

If you’re tired of seeing your /var/log/messages log file full of dropped traffic from APF firewall then we have a solution! We’ll create a separate log file for TCP/UDP OUTPUT and drops which will leave your messages log nice and clean for easy browsing!

Requirements:

APF Firewall 0.9.3 or above. It may work on previous versions but we haven’t tested. If you’re using an older version you should upgrade anyways. Install APF by following our firewall tutorial.

Changing APF’s configuration:

1) Login to your server and su to root shell.

2) Create a new log file just for the TCP/UDP output/drops from APF.
touch /var/log/iptables

Set user permissions to restrict access.
chmod 600 /var/log/iptables

3) Change the syslog so it will tell iptables to use your new log file.
First lets make a backup to be safe:
cp /etc/syslog.conf /etc/syslog.conf.bak

pico /etc/syslog.conf



Article provided by WebHostGear.com

4) Add the following line at the bottom

# Send iptables LOGDROPs to /var/log/iptables
kern.=debug /var/log/iptables

5) Save the changes, ctrl + X then Y

6) Reload the syslogd service for the change to take effect.
/sbin/service syslog reload

7) Open APF and edit the firewall configuration.
First lets make a backup to be safe:
cp /etc/apf/firewall /etc/apf/firewall.bak

pico /etc/apf/firewall

Find the following: DROP_LOG

You should see this: P.S. USE OUR PRINTER FRIENDLY VERSION TO AVOID TEXT WRAPPING, LINK AT TOP!

if [ "$DROP_LOG" == "1" ]; then
# Default TCP/UDP INPUT log chain
        $IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IF -j LOG --log-prefix "** IN_TCP DROP ** "
        $IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IF -j LOG --log-prefix "** IN_UDP DROP ** "

Replace with the following:

if [ "$DROP_LOG" == "1" ]; then
# Default TCP/UDP INPUT log chain
        $IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug
        $IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug

Find the following one more time: DROP_LOG

You should see this:

if [ "$DROP_LOG" == "1" ] && [ "$EGF" == "1" ]; then
# Default TCP/UDP OUTPUT log chain
        $IPT -A OUTPUT -p tcp -m limit --limit $LRATE/minute -o $IF -j LOG --log-prefix "** OUT_TCP DROP ** "
        $IPT -A OUTPUT -p udp -m limit --limit $LRATE/minute -o $IF -j LOG --log-prefix "** OUT_UDP DROP ** "

Replace with the following:

if [ "$DROP_LOG" == "1" ] && [ "$EGF" == "1" ]; then
# Default TCP/UDP OUTPUT log chain
        $IPT -A OUTPUT -p tcp -m limit --limit $LRATE/minute -o $IF -j LOG --log-level debug
        $IPT -A OUTPUT -p udp -m limit --limit $LRATE/minute -o $IF -j LOG --log-level debug


8) Save the changes to firewall.
Ctrl + X then Y

9) Restart apf for the changes to take effect.

/etc/apf/apf –r

10) Make sure the new log file is getting written to:
tail –f /var/log/iptables

You should see things like:

Aug 27 15:48:31 fox kernel: IN=eth0 OUT= MAC=00:0d:61:37:76:84:00:d0:02:06:08:00:08:00 SRC=192.168.1.1 DST=192.168.1.1 LEN=34 TOS=0x00 PREC=0x00 TTL=118 ID=57369 PROTO=UDP SPT=4593 DPT=28000 LEN=14

Also check the messages log to make sure APF still isn’t writing to it.
tail –f /var/log/messages

Final notes:
APF is written by R-fx Networks: http://www.rfxnetworks.com/apf.php

Written by Ramprage

New! - Need server help? Hire an Expert

Get professional help with your configuration, script installation or server issue.
Learn how we can help you with any server problem and make your server run like new. Professional staff will contact you, after submitting a quote request, by phone or email.

Rate this Article :

1

2

3

4

5

6

7

8

9

10
Poor Excellent

Related Articles


� How to install BFD (Brute Force Detection)
� How to install APF (Advanced Policy Firewall)
� Installing Mod_Throttle on cPanel
� Root Check
� Are Flash Hosting Tutorials Worth It?
� Customizing PHP Safe Mode


Discuss this article with others in our new hosting forums

Comments / Feedback

swampy
i tried this tut on apf 0.9.4 and i does not work i get errors when trying to restart apf good job i backed up files first.
pixel
Worked like a charm for me - thx!
ryan
great idea -- will review this for added internal feature.
vijay srivastava
how to remove APF from my server any uninstall procedure.
squalito
I do not have exactly the same lines in my conf.apf.
I have the last version : Apf.0.9.4-6

I updated exisitng lines :
if [ "$DROP_LOG" == "1" ]; then
# Default TCP/UDP INPUT log chain
if [ "$EXLOG" == "1" ]; then
$IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IN_IF -j LOG --log-prefix "** IN_TCP DROP ** " --log-tcp-options --log-ip-options
$IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IN_IF -j LOG --log-prefix "** IN_UDP DROP ** " --log-ip-options
else
$IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IN_IF -j LOG --log-prefix "** IN_TCP DROP ** "
$IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IN_IF -j LOG --log-prefix "** IN_UDP DROP ** "
fi
fi

if [ "$DROP_LOG" == "1" ] && [ "$EGF" == "1" ]; then
# Default TCP/UDP OUTPUT log chain
if [ "$EXLOG" == "1" ]; then
$IPT -A OUTPUT -p tcp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_TCP DROP ** " --log-tcp-options --log-ip-options
$IPT -A OUTPUT -p udp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_UDP DROP ** " --log-ip-options
else
$IPT -A OUTPUT -p tcp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_TCP DROP ** "
$IPT -A OUTPUT -p udp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_UDP DROP ** "
fi
fi


by these lines
if [ "$DROP_LOG" == "1" ]; then
# Default TCP/UDP INPUT log chain
if [ "$EXLOG" == "1" ]; then
$IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug --log-tcp-options --log-ip-options
$IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug --log-ip-options
else
$IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug
$IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug
fi
fi

if [ "$DROP_LOG" == "1" ] && [ "$EGF" == "1" ]; then
# Default TCP/UDP OUTPUT log chain
if [ "$EXLOG" == "1" ]; then
$IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug --log-tcp-options --log-ip-options
$IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug --log-ip-options
else
$IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug
$IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IF -j LOG --log-level debug
fi
fi


and evrything is working fine

Thanks for this article
Squalito
rYno267
When I do
"tail –f /var/log/iptables"

I get this: "tail: .f: No such file or directory
==> /var/log/iptables <==
"

Any Ideas? thanks.
Madlaker
I get the same as Ryno above. I did a locate on iptables and there is no iptables under /var let alone /var/logs.

Is there another step we have to preform?

Any ideas would be appreciated.
Madlaker
Just an update..

Ok, simple solution.

when you restarted the firewall like me, you probably go an error that you missed like I did the first time.

/etc/apf/apf: line 1: ifconfig: command not found

This is because when we are in the su environment instead of su -.

1)just type cd then the enter key
then su - then the enter key

2)now type /etc/apf/apf –r and you shouldn't get that error.

3) Now type tail –f /var/log/iptables and you should see all the drop packets showing up.

If you get any more errors, be sure to look through all the instructions above.
Dennis
I have .9.4 of APF and the lines you say to replace are different in that version. Fir example, here is the first of the two changes I made:

if [ "$DROP_LOG" == "1" ]; then
# Default TCP/UDP INPUT log chain
if [ "$EXLOG" == "1" ]; then
$IPT -A INPUT -p tcp -m limit --limit $LRATE/minute -i $IN_IF -j LOG -$
$IPT -A INPUT -p udp -m limit --limit $LRATE/minute -i $IN_IF -j LOG -$
else

As you see, the "if then else" parts are missing:

if [ "$EXLOG" == "1" ]; then
else

I guessed that I should make the changes and leave these items in although you did not mention them.

The second section I changed per your instructions are here:

if [ "$DROP_LOG" == "1" ] && [ "$EGF" == "1" ]; then
# Default TCP/UDP OUTPUT log chain
if [ "$EXLOG" == "1" ]; then
$IPT -A OUTPUT -p tcp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_TCP DROP ** " --log-tcp-option$
$IPT -A OUTPUT -p udp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_UDP DROP ** " --log-ip-options
else
$IPT -A OUTPUT -p tcp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_TCP DROP ** "
$IPT -A OUTPUT -p udp -m limit --limit $LRATE/minute -o $OUT_IF -j LOG --log-prefix "** OUT_UDP DROP ** "
fi

But I am getting errors, so I suspect something isn't right.

I need some help on this for sure.

Thanks
Izzee
------------------------------------------
DO NOT USE THIS TUTIRIAL FOR APF VERSIONS HIGHER THAN 0.9.3
------------------------------------------

Latest APF version 0.9.6-1
/etc/apf/firewall
Has different $DROP_LOG entries to the ones above.
Now called $LOG_DROP with completely different rules.
No point in this tutorial now as it is obsolete.

RAMPRAGE - This tutorial needs updating as a matter of urgency!!
webhost
I been meaning to ask this in the past but never have untill now.

I restarted the apf and I get this :

[/etc/apf]# ./apf -r
iptables v1.2.9: host/network `-' not found
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.9: host/network `-' not found
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.9: host/network `-' not found
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.9: host/network `-' not found
Try `iptables -h' or 'iptables --help' for more information.

Any idea as to why I am getting this? I dont know about any host/network.

Thanks for you help

 Add Comment
Name
Email
Image Code
Refresh Image

Comments / Feedback



Our site offers free hosting tutorials, cpanel tutorial, web hosting news, shell commands, running a web hosting business, dedicated guides, linux tutorial, apache install, home web server, web server guide, ssh commands, dedicated servers, DNS nameservers, chkrootkit, apf firewall, exim configuration, server compromised, cron backup solution, ftp backup script

Server Tutorials


WebHostGear Reviewed by Ping Zine - Click here

Links:
Lunarpages Coupon