LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-26-2009, 07:59 AM   #1
isak
LQ Newbie
 
Registered: Mar 2003
Posts: 18

Rep: Reputation: 0
DNAT IPtables problem


I am having the following problem with iptables. My situation is as follows:

Client which uses an ISP with a Linux machine(Server 1) with two network cards. Eth0 with ip 1.1.1.2 and gateway 1.1.1.1 these ip's is not public ip's and falls unders the isp's internal range, eth1 with the internal ip range. OpenVPN listen on eth0 for incomming connections. We want to connect to Server1 from external networks. Due to different reasons the isp could not get the routing sorted and give us an public ip on his network. We had to setup another bos (Server2) with eth0 2.2.2.5 and gateway 2.2.2.1 which is public ip's and eth1 with ip 3.3.3.5. Server 2 can communicate via the ISP internal network with server 1. I use DNAT to forward all incomming connections on server 2 to server 1 but the problem I have is that server uses its default gateway for the return packages and does not sent the reply back to server 2. My iptables rules looks as follows on server 2.

/usr/sbin/iptables -t nat -A PREROUTING -p udp -i eth0 -d 196.25.157.135 --dport 1194 -j DNAT --to 192.168.100.170:1194
/usr/sbin/iptables -A FORWARD -p udp -i eth0 -d 192.168.100.170 --dport 1194 -j ACCEPT

Any help on how I can solve the problem would be appreciated.

Thanks

Isak
 
Old 11-26-2009, 01:47 PM   #2
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
iptables -t nat -A PREROUTING -p udp -i eth0 -d 196.25.157.135 --dport 1194 -j DNAT --to 192.168.100.170:1194

By this you tell iptable, that any UDP packets witch come to eth0 with destination address 196.25.157.135:1194 NAT has to change destination address to 192.168.100.170:1194, then ou tell FORWARD them.

Have noticed, that you gave only ONE WAY order.

Packets witch goes back is not TRANSIT packets for iptable!
 
Old 11-26-2009, 02:14 PM   #3
isak
LQ Newbie
 
Registered: Mar 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Thats why I am not sure which other iptables to add. I am missing the point here myself.

Let put the example ip's in my configuration for you and not the ones I just copy and paste from the test server, may be someone can help to build the right iptables.

/usr/sbin/iptables -t nat -A PREROUTING -p udp -i eth0 -d 2.2.2.5 --dport 1194 -j DNAT --to 1.1.1.2:1194
/usr/sbin/iptables -A FORWARD -p udp --dport 1194 -j ACCEPT

Now as per my explanation the reply from server1 does not comes back to 2.2.2.5 but goes to the default gateway of server1 which is 1.1.1.1

Not sure if I have to add specific iptables on server1 as well?

Thanks
 
Old 11-26-2009, 02:30 PM   #4
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Packets will go back to sender.

To the sender's IP.
 
Old 11-26-2009, 02:35 PM   #5
rtspitz
Member
 
Registered: Jan 2005
Location: germany
Distribution: suse, opensuse, debian, others for testing
Posts: 307

Rep: Reputation: 33
As long as it works it doesn't matter which path the returning packages take, no ?
 
Old 11-26-2009, 03:04 PM   #6
isak
LQ Newbie
 
Registered: Mar 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks everyone, got it working. Fault in another firewall rule caused my problem.

Thanks again.
 
  


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 DNAT problem T_Crusher Linux - Security 2 04-11-2007 10:04 PM
iptables DNAT problem eantoranz Linux - Networking 2 09-12-2006 01:00 PM
iptables 1 to 1 DNAT routing problem MarleyGPN Linux - Networking 3 12-13-2005 04:24 PM
Strange problem about iptables DNAT. zufeng Linux - Networking 1 06-28-2003 11:09 AM
problem about iptables DNAT. zufeng Linux - Security 3 06-19-2003 09:29 AM

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

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