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 03-19-2009, 05:50 AM   #1
kristrev
LQ Newbie
 
Registered: Mar 2009
Posts: 10

Rep: Reputation: 0
Outgoing redirection with iptables - TCP skips nat?


Hello,

I am working on configuring a multihomed machine, and one of my goals is to redirect some outgoing TCP-traffic originating from this machine using iptables. Currently, I have got it working with UDP and if I add the rule to the output-chain of the NAT-table before I start the connection, it works.

However, sometimes I want to start doing redirection in the middle of a TCP connection and this does not seem to work. I do not get any matches to my LOG-target and the packets still go through the old interface. In other words, it somehow seems like TCP is skipping the NAT's output-chain. Does anyone have any ideas how to solve this?

The iptables rule I use is:
sudo iptables -A OUTPUT -t nat -p tcp -d 192.168.101.14 --dport 9999 -j DNAT --to 192.168.100.250:9999

Edited: I forgot to add that with my LOG-rule I only see the SYN-packet. The LOG rule is constructed like this:
sudo iptables -A OUTPUT -t nat -p tcp -d 192.168.101.14 --dport 9999 -m state --state NEW,ESTABLISHED,RELATED --sport 1024:65535 -j LOG --log-prefix "INFO,OUTPUT,NAT(tcp): " --log-level debug

Thanks in advance,
Kristian

Last edited by kristrev; 03-19-2009 at 06:18 AM. Reason: Additional info
 
Old 03-21-2009, 06:29 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I know on PREROUTING, only the first packet of a connection traverses the PREROUTING chain. All subsequent packets on that connection are treated in like manner w/o further inspection. I would imagine it is the same way on the nat table OUTPUT chain. If so, you can't do what you are trying to do. Even if you could do it, I don't see how it would accomplish anything since (with TCP) you would never be able to establish the connection with the DNATted address. (The syn packet would have already been sent to the un-DNATted address.)

Last edited by blackhole54; 03-21-2009 at 06:30 AM.
 
Old 03-21-2009, 10:22 AM   #3
kristrev
LQ Newbie
 
Registered: Mar 2009
Posts: 10

Original Poster
Rep: Reputation: 0
You are correct, once conntrack marks a connection as ESTABLISHED the rest of the packets naturally skip the NAT-part. To do what I want to do I need to develop a kernel-module, fortunatly, that looks both doable and fun
 
  


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
Outgoing Packet Redirection Using iptables (FC6) neothephoenix Linux - Server 8 04-25-2008 07:20 AM
not work: iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp --dport 3306 -j DROP abefroman Linux - Security 1 07-18-2007 08:19 AM
Mangled incoming TCP packets confuse outgoing ACK processing Bloomberger Linux - Networking 0 08-10-2006 01:50 PM
Blocking outgoing TCP ¿F M J¿ Linux - Networking 13 09-06-2005 12:59 AM
squidGuard redirection gives TCP miss Recirqie Linux - Networking 4 11-20-2004 04:48 PM

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

All times are GMT -5. The time now is 05:48 PM.

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