can the different hosts (not ip) forwarding to the same port externally? - sockets

Im just wondering, can 2 or more different external hostname/DNS redirect to multiple local servers but same port?
Let's see, I have 2 DNS internet domain for an example, myserver1.com and myserver2.com, and both I have same A record to my forwarded server IP (e.g: 102.123.123.123). Under my server which only has 102.123.123.123 IP address has 2 application servers but instead of trying to make they work, I use different port for each server applications for an example, serverApp1 listening to 0.0.0.0:2010, serverApp2 listening to 0.0.0.0:2020
My point is, is there any way or how to forward my myserver1.com:2000 to serverApp1 (port 2010), and myserver2.com:2000 to serverApp2 (port 2020) but both myserver1.com and myserver2.com has a same A record?
Im quite sure either it is in iptables or /etc/hosts or BIND issues, but guide me if I missed something. And by the way, the servers and DNS records are accessible from the internet which is the firewalls are configured properly. Thanks.

I don't have much experience in that, but I think you will need a third server/firewall/proxy listening for the incoming host and route it accordingly.
Again, I don't have much experience in that, so I'm not sure if the firewall is able to do that.

I think you can use redirection servers like apache.
In my application we want to access lot of intranet servers from internet. So what we did, we configured a apache with all the mappings in httpd.
So when ever a request to apache comes, it will be redirected appropriately.
For example - I have two servers or hostname in intranet : 1) abc.com:7300/context1
2) xyz.com:8900/context2
We configured a apache with host name abcxyz.com:9000. When a request like
abcxyz.com:9000/context1 comes it will be redirected to abc.com:7300/context1 and when a request like abcxyz.com:9000/context2 comes it will be redirected to xyz.com:8900/context2.
In your case since the requests are going through the single server (102.123.123.123), you can use redirection.
Hope it helps.

Related

Is there a way to make Virtualmin listen on a domain instead of ip+port

I have created a virtualmin account to manage multiple servers instead of cPanel and after reading all of the documentation I have yet to see why my subdomain does not load under port 10000.
I'd like to have some form of control if I do plan on giving other users accounts, without having to have them use an IP which does not allow port 443.
After finishing installation they gave me my IP with port 10000
and my domain with port 10000 and the only one that loads is the IP address.
Problem solved. To anyone on Debian facing this issue, run a virtualhost and use a reverse proxy to load the url containing port, and disable SSL only.
You should have panel.example.com running your virtualmin control panel.

Adding subdomain pointing to same IP but different port

I have a domain name registered at ovh.com, let's say it's called domain.com.
This domain is pointing on my router's public IP, then I redirect the https port 443 of my router to my server port 443. So when we go to domain.com it redirects to my server:443.
To be more accurate, domain.com just redirect to my router's public IP. So for example if I use a graphic database manager, I can tell him that the server address is domain.com:[SGBD port] and It will works.
But all my applications are running on this same server. And to add a little more security, I am not using the usual port for all protocols. So let's say my port are the following :
git : 50000
SGBD : 55000
cloud : 60000
website 65000
and some others, for example some TCP ports between 40000 and 50000.
My git and my cloud have a graphical manager I can access by typing domain.com:50000 or domain.com:60000 in my web browser from everywhere. I use the same URL on all my software. domain.com:50000 for my git client, domain.com:55000 for my database client and so on.
This way is working perfectly but there are 2 problems annoying me :
The first one is that I have to tell the port number to everyone who's susceptible to use my applications. But like I said I am not using usual port number for a little more security so I don't want to share these numbers with everyone.
The second problem is more important :
When I am somewhere, for example at work, it's possible that the firewall is blocking the port numbers I am using. So my personal git isn't accessible, same for my cloud etc.
To solve these problem in one move I wanted to add subdomain on my domain and redirect these subdomain to my differents ports. For example :
website : domain.com:65000
git.domain.com ==> domain.com:50000
SGBD.domain.com ==> domain.com:55000
cloud.domain.com ==> domain.com:60000
So in my mind, with this solution I can type git.domain.com in my browser to initiate the communication by https (the https port is almost never blocked), then redirect it to my router's port 50000 from OVH then my router redirect it to the git port of my server.
But obviously this would be to good to be truth.
When creating a subdomain (at least on OVH ?) we can't specify a port. So I can't set git.domain.com is redirecting to myRouterIp:50000 but just to myRouterIp. So with a web browser, typing git.domain.com will redirect to myRouterIp:443, which is already taken by my website.
So i'm a little confused. Do I have to buy one router with a different public IP per application then making all differents subdomain pointing on a different router ? I almost sure it's a bit ridiculous. How do you think I can solve it ?
As you correctly noticed, in your DNS console you can't specify port; the reason is that DNS does not care about ports, its only purpose is to resolve hostnames to IP addresses.
Another thing important for your problem is that most (non http) application clients will, even if they use friendly hostname, resolve that name to IP address before initiating the connection to your router/server, and then use that IP address for communicating to router/server. That means that when request reaches a port on your router/server, there will be no way for router/server to determine which hostname was initially used.
The rare exception to this is HTTP, where the browser is always sending the requested hostname in Host HTTP header. That means that you can run multiple different websites on one IP address on the same port (that is how shared web hosting works, for example). Setting this up should be pretty straightforward, but is probably out of scope on SO, try SF or SU.
For other (non HTTP services), the only solution is to run them on different ports (which you already do), or to have multiple public IP addresses (which might be difficult to get from your ISP). Also, running non-http services on some random non-default ports (and telling that port number to your users) might be (very sightly) more secure than running them on their respective default ports.
Depending on your use case, one other possible solution would be to have your users connect to your local network using secure VPN, and after that they could have access to your services (which would run on different private IP addresses and any port you like).

Hosting a website using server software

How can i host a website through my computer using server softwares?
I tried to host a website through my own computer using apache tomcat server but it didnt work ( please briefly explain every point )
The main issue that you need to deal with is getting the clients to your computer.
Yes, it is possible and yes I have done it, albeit a while ago.
You need to see if you can browse to your computers website from another device on your network, this will ensure that apache is working. Try another computer/laptop/tablet/whatever to see if this site reachable by other computers using the IP Address and possibly port number. If you cannot get to the site, there are settings in apache to deny certain ip's, google it to get the exact steps for your version. If it works, move on to step 2.
You will need a static IP Address to ensure that all further steps stay working, google this if you are not sure how to do it
You need to have the external IP address of your router(whatsmyip.org) or use Dynamic DNS to route traffic from an address to your ip and there are services that allow this. I can recommend no-ip.com - This is all assuming that you have access to the router.
You would be required to set up port forwarding on your router. This will direct the internet traffic to your computer. You will need to get the exact instructions for your specific model of router.
Please be aware that you need to have proper firewalls and systems in place to prevent attacks. I am sure that you are just testing at this point though...
All the best!

Pointing a domain to my remote Node JS application?

I'm trying to work out how exactly to deploy Node JS on my Ubuntu 10.04 LTS server. I've read many different blogs and articles that explain multiple different ways. Most seem out of date, or don't really work it seems.
It seems that the simplest solution is to use something like Forever? ...or Upstart with Monit or Supervisor. Is that correct?
One thing that I still don't understand though is without using something like Ngnix, how would I actually get my domain name (such as example.com) to actually point to my Node JS application and it's running port?
Many thanks for any guidance. I'm not an expert with this, so please excuse my lack of knowledge here. (I'm trying my best! :)
UPDATE: The reason why I'm asking this is on my server I have Ngnix running for my static/Django projects. I'm wanting to use the same server for some example Node JS applications I'm messing around with. I've followed the link about vhosts and Connect with Node JS, and this is good to a point, but I'm still not understanding how I would get one of my domains to actually point to this Node application on my server?
You need to separate the notion of the domain name from the actual server. The domain name points to a server. When the browser (or other client) asks for example.com, DNS looks up the associated IP address and directs the browser to the server at that IP address.
The browser then chooses which port to send its request through by looking at the URL. For example, a request for example.com:345 will select port 345. If left unspecified, by default, when using HTTP, it uses port 80.
So the browser has sent its request through port 80. Now, on your server, there is a program listening to that port. For you, it would nginx. Nginx reads the request ("oh, you're looking for index.html") and delivers back the contents you requested.
In your scenario, Node.JS replaces Nginx. For Node.JS to respond, it would also need to listen to a port and respond appropriately. That's where your code comes in:
require('http').createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
This starts a server, listening at port 1337. Any requests directed to example.com:1337 would be responded to by this Node.JS application with a "Hello World".
tl;dr: Your domain name already points to your server. You can access your application at example.com:1337, where 1337 is your port.

Go to specific server depending on which is up?

I have two servers, in different locations, running the same site (the second one, i think, would be called a "mirror"). I prefer the first one, but it has not-so-good uptime. I would like to create a website (in Javascript, HTML, Silverlight, or ASP.NET C# if possible) that checks if website #1 is up, and (if it is up) send the user there. If it's not up, it should forward the user to server #2. How can I check if the server is up (like http://isup.me/) and how can i forward the user there? Thanks!
There are many DNS providers that will do this for you automatically. The feature is called "Failover DNS" and it works like this:
for your domain e.g. example.com, you'd set an A record for the IP of server #1 (say it's ip is 123.123.123.123)
example.com A 123.123.123.123 TTL: 300s
www.example.com would be a CNAME to example.com
Then you would add server 2's IP address to the failover list for example.com. Then the provider will check server #1 every few minutes to see if it's up. Most providers allow you to configure how often and what to check to determine that it is indeed up.
If server #1 is down, the provider will start serving Server #2's ip address, so all traffic will be directed there.
You can read more about it here: http://www.dnsmadeeasy.com/enterprisedns/dnsfailover.html
Another provider that supports this is zerigo.com
If you are working for a company and scaliablity is a concern in future , please use some loadbalancer which automatically does it for you.
there are various options with loadbalancer to load the balance and route the traffic.
If you're using IIS 7, take a look at this article about Load Balancing.
http://learn.iis.net/page.aspx/486/http-load-balancing-using-application-request-routing/