LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-26-2014, 12:32 PM   #1
yenn
Member
 
Registered: Jan 2011
Location: Czech Republic
Distribution: Slackware, Gentoo, FreeBSD
Posts: 176

Rep: Reputation: 28
Iptables double NATing


I'm currently experiencing odd behavior with iptables. Some virtual machines use own hypervisor as default gateway (to mitigate single point of failure), meanwhile few others use different gateway on different hypervisor. All gateways are on the same subnet.

While simple masquerade rule works with local VM - local hypervisor setup, it does double NATing otherwise.

Code:
 
iptables -A POSTROUTING -s 192.168.34.0/24 ! -d 192.168.34.0/24 -j MASQUERADE
Let's say VM has default gw 192.168.34.1 and it actually run's on hypervisor with ip 192.168.34.3
Packet will traverse NAT like this:
Code:
VM (192.168.34.5) -> [Hyper #1 NAT] (192.168.34.3) -> Gateway [Hyper #2 NAT] (192.168.34.1) -> Outer network
While I think I understand why this rule doesn't do exactly what I want, I'd like to know how to write iptables rules like:

1) If destination is in outer network and default gateway is not local, pass the packet to gateway.
2) If destination is in outer network, NAT packet and forward it.

Is it possible if packet only contains src and dst ip address?

And please don't suggest placing virtual machines "close" to it's gateway, it's not possible and even not desired right now (distributing load and logical separation of VM's across physical servers).

Last edited by yenn; 05-26-2014 at 01:02 PM.
 
Old 06-10-2014, 12:49 PM   #2
foodown
Member
 
Registered: Jun 2009
Location: Texas
Distribution: Slackware
Posts: 611

Rep: Reputation: 221Reputation: 221Reputation: 221
Can we see a packet capture with some test traffic?
 
  


Reply


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
port based nating with iptables shiladitya Linux - Security 4 10-08-2013 03:58 AM
string based nating using iptables. advaitraut Linux - Newbie 1 09-23-2009 01:28 PM
Static Nating via iptables maliha Linux - Networking 5 01-09-2007 01:00 PM
iptables twice nating beno123 Linux - Networking 0 07-27-2005 02:41 AM
IPTables Undesired NATing Wraezor Linux - Security 3 07-15-2005 05:09 AM

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

All times are GMT -5. The time now is 07:31 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