LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   access private ip from public ip (https://www.linuxquestions.org/questions/linux-server-73/access-private-ip-from-public-ip-4175459281/)

pasin 04-23-2013 08:49 AM

access private ip from public ip
 
Hello everybody!
Hoping I am in the right part of the forum,
I need to know how can I practically create this scenario.
I have a server with a private ip which can be accessed from outside through a public ip.
But I need to also access another server(private ip) through the public ip that I have from the first server.
So for exampe
I have server1 with prc ip 192.168.1.x that can be accessed from outside through and public ip(x.x.x.x)
I also have another server 192.168.1.y. I need to access this server through for example x.x.x.x/sth to point to the second server.

lleb 04-23-2013 10:45 AM

you would set it up the same way you setup the first server. NAT is your friend.

you just can not have the same port forwarded to multiple private IPs.

theNbomr 04-23-2013 11:26 AM

First, explain the nature of the public/private server. Is it running a modern-ish version of Linux? It does have two network interfaces?

In general terms, the public/private server will need to become a router, and it will need to port-forward a public IP port to the private LAN IP/port. This will involve the use of netfilter rules, which you configure from userspace using the iptables utility. Generally, the ruleset is crafted as a shell script that you run to establish or alter the behavior of the router. Without having a fairly sound understanding of such rules, your easiest and best approach would be to use a canned package that provides a way to add this. I use and like HomeLanSecurity; there are others which also support the topology I assume your are using now.

--- rod.

eklavya 04-24-2013 12:56 AM

In your router setting, you have defined your server's LAN's IP as static IP (public IP).
Suppose your server's LAN IP is 192.168.1.9 and your static IP (public IP) is 109.89.85.3.
You have defined it in your router setup that this LAN IP should be accessible as public IP.

Now you want to do that different system of same LAN should act as a server. There are two ways.
1) Change the defined LAN IP for public IP in router setup and set the LAN IP of your new system there.
2) Change the LAN IP of your current server and give this IP to your new system.so the system will become server.

pasin 04-24-2013 01:07 AM

What I am trying to do in more simple words is:
I have 2 servers, each one containing a web site, but I have only one public ip.
The first prv ip is associated with the public ip, but how can I acceess also the other private ip using the same public ip?
I have installed Centos 5.5

TenTenths 04-24-2013 02:23 AM

Install Squid on the box with the public facing IP and then use squid as a "reverse proxy" There's quite a few threads on here about it, just search for squid reverse proxy I've never done it, just seen similar questions asked on here.

eklavya 04-24-2013 04:59 AM

You can access only one server at a time with public IP.
You will have to change the private IP of server which one you want to make active.

TenTenths 04-24-2013 05:22 AM

Quote:

Originally Posted by eklavya (Post 4937878)
You can access only one server at a time with public IP.

Not exactly correct:

1) A slight expansion on my previous post:
http://wiki.squid-cache.org/SquidFaq/ReverseProxy
"The Squid redirector can make one accelerator act as a single front-end for multiple servers. If you need to move parts of your filesystem from one server to another, or if separately administered HTTP servers should logically appear under a single URL hierarchy, the accelerator makes the right thing happen."
2) Using different ports (now quite what the OP had in mind, but easily do-able with most good routers).
Just random thinking as I've never tried it but could have a global redirect on the server listening on port 80 to redirect all requests to the folder /blah to http://w.x.y.z:81/blah
3) "Appliances"
We use several of these and use a single public IP to access 3 web servers.

theNbomr 04-24-2013 11:06 AM

Quote:

Originally Posted by pasin (Post 4937727)
What I am trying to do in more simple words is:

We don't need things to be simplified; we need more details.
I've already asked for those details. Without knowing what you already have, no one can produce a relevant answer.
If your 'server' is a Linux host with two ethernet interfaces, then a solution should be quite simple. We need you to describe the network topology, and the nature of all of the hosts involved, especially the OS and any network related hardware.

--- rod.

spartha 04-24-2013 10:25 PM

I did this
 
Quote:

Originally Posted by pasin (Post 4937727)
What I am trying to do in more simple words is:
I have 2 servers, each one containing a web site, but I have only one public ip.
The first prv ip is associated with the public ip, but how can I acceess also the other private ip using the same public ip?
I have installed Centos 5.5

Well, first can you access your second server from your first? If no, get the reachability between these two.

We are going to make Serv1 as a router/firewal and webserver.

Are you using urls to access both the websites or ip/port? if using urls -
- use your dns to map the 2 urls to two different ports for the public ip. (x.x.x.x: port1 for serv1 and x.x.x.x: port2 for serv2 where x.x.x.x is your public ip)
- Now enable ip forwarding on serv 1 (http://www.ducea.com/2006/08/01/how-...ding-in-linux/)
- use ip tables to perform NAT and map x.x.x.x: port1 to serv1:80 and x.x.x.x: port2 to serv:80 (http://www.howtoforge.com/nat_iptables)

let me know if you have specific questions in doing this.

- Partha


All times are GMT -5. The time now is 04:49 AM.