LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 05-25-2007, 03:49 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Rep: Reputation: 31
Routing Problem with IPTables


Hey Guys I have the following setup:

eth0:1
ISP--- -DEBIAN-eth2--Switch--Internal Web Server
eth0:2

I have one ethernet cable from my ISP on which I have two Public IPs assigned A&B I have natted all the traffic coming to IP B directly to my Internal web server with IP C.
This scenario was applied succesfully.
However the other clients on the network and the webserver itself have to be able to access the webserver using IP B (i.e. the public IP) NOT the private IP C.
Naturally if the IP B is entered into a web browser it will take them to the Apache server on the debian router since this is the server hosting IP B.


This is the typical routing rule
iptables -t nat -A PREROUTING --dst $B -p tcp --dport 80 -j DNAT \
--to-destination $C

Now according to http://iptables-tutorial.frozentux.n...-tutorial.html

Adding This should work :

iptables -t nat -A POSTROUTING -p tcp --dst $B--dport 80 -j SNAT \
--to-source $C

But it did not work ...if the rule above is added without specifing a port. Pinging IP B "The public IP" from a local computer on the LAN..it will say reply from IP C "i.e. from the local webserver". However if the IP B is entered into a web browser it will just stay loading forever.

Thanks for any suggestions or clarifications
 
Old 05-27-2007, 02:10 PM   #2
Brian1
Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,697

Rep: Reputation: 61
From my understanding you need another dnat rule. Check this post out.
http://www.linuxquestions.org/questi...highlight=dnat

Brian
 
Old 05-27-2007, 02:37 PM   #3
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Original Poster
Rep: Reputation: 31
Thanks for the hint brian1 I did try that as my link already shows..adding to that..that tutorial about IPTABLES is the best I have ever read. I will try it again..and post results.

P.S. Iam using a masquerade SNAT rule in my script..could this be causing the problem...I cannot test this since Iam logging in remotely and disabling this would prevent me from accessing the servers.

Last edited by ALInux; 05-27-2007 at 02:38 PM.
 
Old 06-01-2007, 07:47 AM   #4
zsoltrenyi
Member
 
Registered: May 2004
Distribution: redhat, trustix, debian
Posts: 103

Rep: Reputation: 15
is youre web server accessible from the internet vi ip B?

is your web server and the other other clients on the network are on the same subnet?
because if that's the case then this happens: client trying to get to ip B send's packet to router, router redirects packet to ip C, now webserver see's that source address is on the same subnet and send's packet directly to host on the network with his ip address (C) as source address. But host on the network is expecting ip B as source address as he initiated the connection to ip B.
 
Old 06-01-2007, 08:21 AM   #5
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Original Poster
Rep: Reputation: 31
Good thinking zsoltrenyi...this is exactly the case but how can I solve this dilemna
 
Old 06-01-2007, 08:47 AM   #6
zsoltrenyi
Member
 
Registered: May 2004
Distribution: redhat, trustix, debian
Posts: 103

Rep: Reputation: 15
You have to force ip C to go through the router to access the other computers on the network

One way would be to change the subnet mask of your web server ip C to be in a different subnet of the rest of your network but in the same subnet of the routers IP
example subnetmask of 255.255.255.252 means a subnet of 2 usable IP adresses 192.168.61.1 and 192.168.1.2 so if your router is 192.168.1.1 and web server 192.168.1.2 then anything else beyond 192.168.1.4 goes through the router. Router can keep subnet mask 255.255.255.0 .
Other way would be to change completely the IP class of the web server and configure an alias for your internal interface on your router with an ip of the same IP class
And third I'm not sure but you can try to remove the route towards your network from webserver C and replace it with a route to router's ip adrress on interface eth.....
 
Old 06-01-2007, 09:48 AM   #7
zsoltrenyi
Member
 
Registered: May 2004
Distribution: redhat, trustix, debian
Posts: 103

Rep: Reputation: 15
maybe (I.m not sure but you can try) you can SNAT traffic from network with dest address ip B and dport 80 to address B then for webserver would appear that the connection is coming from ip B and the response will go to ip B
So instead of iptables -t nat -A POSTROUTING -p tcp --dst $B--dport 80 -j SNAT \
--to-source $C (which doesn't make much sense) try:
iptables -t nat -A POSTROUTING -p tcp -s $own_network --dst $B--dport 80 -j SNAT \
--to-source $B
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables NAT routing problem marpel Linux - Security 10 05-09-2006 07:23 AM
Iptables routing problem GGery Linux - Networking 4 03-28-2006 01:49 AM
iptables 1 to 1 DNAT routing problem MarleyGPN Linux - Networking 3 12-13-2005 04:24 PM
iptables/routing problem Mephisto123 Linux - Networking 1 07-18-2005 07:50 AM
Routing and IPtables problem RajaRC Linux - Networking 10 01-10-2005 07:17 AM


All times are GMT -5. The time now is 06:37 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration