LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2012, 03:42 PM   #1
sergey.by
LQ Newbie
 
Registered: Jul 2012
Posts: 3
Blog Entries: 1

Rep: Reputation: Disabled
Question iptables: log connection after SNAT/MASQUERADE command


Hello!

I have the following problem with iptables in Debian 6:

My server works as a router and it needs to log server external IP+port for all outgoing connections.

But after command SNAT or MASQUERADE traffic is "lost".
I mean no following rules can catch those traffic.
Everything looks like SNAT/MASQUERADE is the "end" rule and it pushes traffic to network immediately.

Question:

How can I log routed connection data with server external IP and port?
 
Old 07-18-2012, 06:39 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Please post your complete rule set instead of talking about the problem.
 
Old 07-19-2012, 04:18 AM   #3
sergey.by
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
These are rules from nat table:

-A POSTROUTING -p tcp -s 10.0.0.0/8 --syn -j MARK --set-mark 4
-A POSTROUTING -m mark --mark 4 -j LOG --log-prefix "TCPLO1 " --log-level debug
-A POSTROUTING -s 10.0.0.0/8 -o eth0 -j SNAT --to-source 12.23.34.56
-A POSTROUTING -m mark --mark 4 -j LOG --log-prefix "TCPLO2 " --log-level debug
-A POSTROUTING -p tcp --syn -j LOG --log-prefix "TCPLO3 " --log-level debug

First rule marks routed connection
second - logs marked connection but it don't contain IP and port selected by NAT.
third - executes SNAT
and next line don't log anything but should log marked connection
last line should log any connections and it logs server's own traffic and not routed connections

Last edited by sergey.by; 07-19-2012 at 04:19 AM.
 
Old 07-19-2012, 04:31 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by sergey.by View Post
and next line don't log anything but should log marked connection
Are you certain that should be the case? Hasn't the first packet in the connection already exited the chain by the SNAT target?
 
Old 07-20-2012, 01:55 AM   #5
sergey.by
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
I'm not sure.

But I need to log those first packet leaving the chain.
 
Old 07-20-2012, 09:52 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Then according to how the NAT table POSTROUTING chains works just having
Code:
-A POSTROUTING -s 10.0.0.0/8 -j LOG --log-level debug --log-prefix "TCPLO1 "
-A POSTROUTING -s 10.0.0.0/8 -o eth0 -j SNAT --to-source 12.23.34.56
should do AFAIK.
 
  


Reply



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 SNAT doesn't work on second leg connection Khaosmaker Linux - Networking 7 03-28-2012 08:28 AM
Quagga for Linux Routing without SNAT or MASQUERADE. Zepiroth Linux - Networking 1 03-12-2007 11:01 AM
Need a few hints re. SNAT, Masquerade, etc. BurntChips Linux - Networking 9 01-24-2007 11:40 AM
MASQUERADE vs. DNAT/SNAT Palula Linux - Networking 9 08-12-2005 10:23 AM
Masquerade or SNAT nesbituk Linux - Networking 5 09-08-2004 04:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:13 AM.

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