LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-27-2012, 10:48 PM   #1
perlkad
LQ Newbie
 
Registered: Jul 2012
Posts: 2

Rep: Reputation: Disabled
IPTABLES - nat with multiple translated sources


Hello,

For iptables, I have the following topology with 2 physical interfaces: eth0(WAN) and eth1(LAN). Also I added some virtual interfaces to support additional ip addresses.


WAN ---- eth0 (110.120.130.140/24) ---- eth1 (10.20.30.40/24) ---- 1.2.3.4/24
---- eth0:1 (110.120.130.141/24) ---- eth1:1 (10.20.30.41/24)
---- eth0:2 (110.120.130.142/24) ---- eth1:2 (10.20.30.42/24)



Currently I have the following iptables with the translation path taken.

-A PREROUTING -d 110.120.130.140 -p tcp -m tcp --dport 80 -j DNAT --to-destination 1.2.3.4:80
-A PREROUTING -d 110.120.130.141 -p tcp -m tcp --dport 80 -j DNAT --to-destination 1.2.3.4:80
-A PREROUTING -d 110.120.130.142 -p tcp -m tcp --dport 80 -j DNAT --to-destination 1.2.3.4:80
-A POSTROUTING -d 1.2.3.4 -j MASQUERADE

110.120.130.140 -> 10.20.30.40 -> 1.2.3.4
110.120.130.141 -> 10.20.30.40 -> 1.2.3.4
110.120.130.142 -> 10.20.30.40 -> 1.2.3.4


I want to do the NAT based on the below paths instead, so that the device (1.2.3.4) will see packets coming from different source ip.

110.120.130.140 -> 10.20.30.40 -> 1.2.3.4
110.120.130.141 -> 10.20.30.41 -> 1.2.3.4
110.120.130.142 -> 10.20.30.42 -> 1.2.3.4


What else should be added to the iptables?

Thanks
 
Old 07-30-2012, 04:00 AM   #2
Argief
LQ Newbie
 
Registered: Mar 2010
Location: South Africa
Distribution: Undecided
Posts: 28

Rep: Reputation: 0
Your iptables is only changing the destination address, not the source address. Try SNAT.
 
Old 07-30-2012, 09:25 PM   #3
KinnowGrower
Member
 
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
I dont know why you added more virtual WAN interfaces. What i know is on the destination side you can round robin the IPs .eg. To DNAT to 4 ip address (1.2.3.4, 1.2.3.5, 1.2.3.6, 1.2.3.7) instead of one (1.2.3.4) you can write the following IPtbales rule

Quote:
-A PREROUTING -d 110.120.130.140 -p tcp -m tcp --dport 80 -j DNAT --to-destination 1.2.3.4-1.2.3.7
You can try on the Wan side. means Did you tried the following rule?
Quote:
-A PREROUTING -d 110.120.130.140-110.120.130.142 -p tcp -m tcp --dport 80 -j DNAT --to-destination 1.2.3.4:80
May be helpful for you

Last edited by KinnowGrower; 07-30-2012 at 09:40 PM.
 
  


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
pptp multiple clients behind iptables nat saf Linux - Networking 4 08-06-2012 02:43 PM
IPTABLES - nat with multiple translated sources perlkad Linux - Security 1 07-28-2012 01:07 PM
iptables: can't initialize iptables table `NAT' linuxgentoo Linux - Kernel 3 01-17-2010 10:15 AM
iptables NAT to multiple vlans? ACiD GRiM Linux - Server 0 03-26-2009 12:24 AM
multiple sources with iptables doronunu Linux - Security 4 06-05-2006 01:27 AM

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

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