LinuxQuestions.org
Review your favorite Linux distribution.
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 02-06-2009, 02:31 AM   #1
Avdaga
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Rep: Reputation: 0
Multiple public IP's - not reachable from inside


For my lan I am using range 192.168.0.
For internet I have 2 ip addresses.

The primary WAN ip 1.1.1.1, is used for my main server (mailserver, webserver, proxy etc). This server takes care of the routing as well... It's ip on the LAN is 192.168.0.1

Now I have a secondary server on LAN ip 192.168.0.2, which i route to WAN ip 1.1.1.2.

iptables rules used:
-A PREROUTING -d 1.1.1.2 -j DNAT --to-destination 192.168.0.2
-A POSTROUTING -s 192.168.0.2 -j SNAT --to-source 1.1.1.2

It is reachable on WAN ip 1.1.1.2 and when connecting to a WAN address is is also seen as 1.1.1.2. All working fine.

The problem is that when i try to connect to 1.1.1.2 from the LAN, i can not reach it. It is reachable on 192.168.0.2, but I want it reachable on the WAN address as well.

Any ideas anyone?
 
Old 02-06-2009, 04:24 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Shouldn't you be reaching your own servers (on 192.168.0.0/24) from the lan using their local IP addresses.

If the internet servers where in a DMZ, which you probably should do, you would use your gateway firewall as the default gateway and reach them as you would any internet address.
 
Old 02-06-2009, 07:04 AM   #3
Avdaga
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
Shouldn't you be reaching your own servers (on 192.168.0.0/24) from the lan using their local IP addresses.

If the internet servers where in a DMZ, which you probably should do, you would use your gateway firewall as the default gateway and reach them as you would any internet address.
The first server is directly connected to the ISP over optic fiber and is the gateway for the second server: we have 5 WAN IP addresses, which have to be routed by the first server.

The routing goes fine when accessed from WAN, and accessing WAN, but for some reason not when accessed from the LAN
 
Old 02-06-2009, 09:26 AM   #4
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
You shouldn't be routing packets from your internal network out over the external interface on your firewall and then back in again. Just setup your DNS with split views so that internal clients are answered with the internal IP address, and all other clients (external) will get the external IP address. You could also do this with hosts files as well.
 
Old 02-06-2009, 10:37 AM   #5
compucoder
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Rep: Reputation: 0
I had this same issue and learned how to get past it.

I can only tell you the Shorewall way of doing it and you'll have to translate it to raw IPTables:

Add new FW rules to go from LAN to WAN - inside to out basically. I.e.

DNAT LAN WAN:192.168.1.23 tcp 80,443 - 1.1.1.2

You then need to add a rule in your SNAT or MASQ table (not sure) to NAT it back into your LAN to the right IP:

eth0:192.168.1.23 eth0 192.168.1.1 tcp 80,443

eth0 is my internal interface (LAN)

These rules are just doing ports 80 and 443 - if you need to do all ports on the IP then you'll have to remove those.

I hope this helps you out.
 
Old 02-06-2009, 10:56 AM   #6
Avdaga
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chort View Post
You shouldn't be routing packets from your internal network out over the external interface on your firewall and then back in again. Just setup your DNS with split views so that internal clients are answered with the internal IP address, and all other clients (external) will get the external IP address. You could also do this with hosts files as well.
Hmm guess setting up a seperate DNS view is a solution since it will omit the IP address...
The only problem is that the internet domain is hosted at the ISP, and I would have to add all subdomains existing (and created in the future) to my local view... It is not possible to add a single record as in the hosts file, is it?
 
Old 02-06-2009, 01:15 PM   #7
Avdaga
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by compucoder View Post
I had this same issue and learned how to get past it.

I can only tell you the Shorewall way of doing it and you'll have to translate it to raw IPTables:

Add new FW rules to go from LAN to WAN - inside to out basically. I.e.

DNAT LAN WAN:192.168.1.23 tcp 80,443 - 1.1.1.2

You then need to add a rule in your SNAT or MASQ table (not sure) to NAT it back into your LAN to the right IP:

eth0:192.168.1.23 eth0 192.168.1.1 tcp 80,443

eth0 is my internal interface (LAN)

These rules are just doing ports 80 and 443 - if you need to do all ports on the IP then you'll have to remove those.

I hope this helps you out.
That's practically what I have done with the rules:
-A PREROUTING -d 1.1.1.2 -j DNAT --to-destination 192.168.0.2
-A POSTROUTING -s 192.168.0.2 -j SNAT --to-source 1.1.1.2


Or am I interpreting your solution incorrectly?
 
Old 02-06-2009, 06:38 PM   #8
compucoder
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Rep: Reputation: 0
Quote:
Originally Posted by Avdaga View Post
That's practically what I have done with the rules:
-A PREROUTING -d 1.1.1.2 -j DNAT --to-destination 192.168.0.2
-A POSTROUTING -s 192.168.0.2 -j SNAT --to-source 1.1.1.2


Or am I interpreting your solution incorrectly?
I don't know IPTables but from looking at this I think you are.

Maybe something like this:

iptables -A POSTROUTING -s $INTERNAL_NET -d $INTERNAL_IP \
-j SNAT --to-source $NAT_IP

I found this on a blog - says this final rule makes it so you can hit the public IP from the LAN. You'll have to plug in your values.

Maybe someone with IPTable experience can explain what should go in each variable.

I use Shorewall for everything and it really shields you from the nitty gritty of IPTables.

I hope you can do something with this line of code.
 
Old 02-06-2009, 06:52 PM   #9
compucoder
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Rep: Reputation: 0
Try this post as well - it may help:

http://www.dslreports.com/forum/remark,15532090
 
Old 02-07-2009, 07:31 PM   #10
Avdaga
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by compucoder View Post
I don't know IPTables but from looking at this I think you are.

Maybe something like this:

iptables -A POSTROUTING -s $INTERNAL_NET -d $INTERNAL_IP \
-j SNAT --to-source $NAT_IP

I found this on a blog - says this final rule makes it so you can hit the public IP from the LAN. You'll have to plug in your values.

Maybe someone with IPTable experience can explain what should go in each variable.

I use Shorewall for everything and it really shields you from the nitty gritty of IPTables.

I hope you can do something with this line of code.
It is not really clear to me WHY this rule is doing the job, but it sure is

-A POSTROUTING -s 192.168.0.0/24 -d 192.168.0.2 -j SNAT --to-source 1.1.1.2

Thanks a lot for your help compucoder, really appreciate it

greetz
 
Old 02-07-2009, 07:33 PM   #11
compucoder
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Rep: Reputation: 0
Quote:
Originally Posted by Avdaga View Post
It is not really clear to me WHY this rule is doing the job, but it sure is

-A POSTROUTING -s 192.168.0.0/24 -d 192.168.0.2 -j SNAT --to-source 1.1.1.2

Thanks a lot for your help compucoder, really appreciate it

greetz
I felt the same way when I found the Shorewall rules to do this. I found it very non intuitive. But, hey, it works and I'll take it!
 
  


Reply

Tags
iptables, routing



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
NAT to different Public IP's compucoder Linux - Networking 1 01-29-2009 09:26 PM
Howto setup iptables firewall and DMZ with multiple public IP's ? hendrixx Linux - Networking 2 11-30-2008 08:03 AM
"ip" command / Multiple public IP's Jaidan Linux - Networking 3 09-23-2007 01:14 AM
IPTables - Multiple Public IP's to private IP's matneyc Linux - Security 8 05-27-2005 12:23 PM
adding public ip's TurboChicken Linux - Networking 3 11-12-2004 06:58 AM

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

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