Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-07-2008, 02:00 PM   #1
LQ Newbie
Registered: Mar 2008
Posts: 7

Rep: Reputation: 0
iptables port forwarding logging

After looking up numerous forums, including here, I got my port forwarding to work. It's something like this:

echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 22022 -j DNAT --to
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 22023 -j DNAT --to
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -p tcp --dport 22 -j ACCEPT

Now my question is, how do I log these port forwards to a specific place, something like /var/logs/portfowards.log?

Old 07-08-2008, 12:12 AM   #2
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
You can put a rule with a LOG target into the NAT table with the same conditions as the DNAT rule. eg
 /sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 22022 -j LOG --log-prefix PortForward:
Put this just before the corresponding DNAT rule, and you will get stuff in the /var/log/messages file by default. To put them into another file, you have limited choices with the standard syslog facilities. A better scheme uses syslog-ng, which gives you more flexibility in sorting and routing log messages.
Old 07-08-2008, 11:15 AM   #3
LQ Newbie
Registered: Mar 2008
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks. I can't seem to figure out how to use the syslog. I'm using a Fedora 9. I have an rsyslog but I don't know how to use that.
Old 07-08-2008, 11:41 AM   #4
LQ Newbie
Registered: Jun 2008
Posts: 5

Rep: Reputation: 0
I know it's a bit late...
but try looking at this link...perhaps you will find something can help you:


forwarding, iptables, log, logging, port

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables port forwarding _kure_ Linux - Networking 7 01-16-2012 05:19 AM
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 08:35 PM
iptables port forwarding abdul_zu Linux - General 1 02-05-2006 04:39 AM
port forwarding with iptables kkennedy Linux - Networking 1 09-01-2005 07:48 PM
iptables port forwarding jefmwols Linux - Networking 9 05-20-2005 05:08 PM

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration