port forwarding

dyndns.org IP sending
Of course many of us know already dyndns.org website, which has been offering since years the possibility to get a domain name for free. For instance my private domain is theblackcat.dyndns.org. Since I don't have a static IP address at home, but the dynamic IP address provided by my dear ISP, I use dyndns.org. All I do is send to dyndns.org my IP address, on a regular basis. Uh in fact I used to, but since my router can do the job in my back, I let it handle it. I also tell it to handle wildcards so any subdomain will also be routed to me. More about that feature later...
I have Apache running on my G5. Nothing fancy, I tell my router to reroute all trafic coming on port 80, to my G5. So basically at this point I have a webserver behind a router, getting requests on port 80 for the default host, through a NAT router. Please note that in order to make sure that the port forwarding rule always works you will need to tell the router to associate the internal IP address 192.168.0.2 (in my example) to your web server's physical MAC address. If you don't do that and restart all your network, the NAT router will have all the bandwidth to address local addresses randomly, kinda first come first serverd. You don't want that. You need to harden the IP address of your web server, for the web services. If you have other components running on some other machines (say, a VNC service you need to access remotely) same rule, you'll need to give that other server a local IP address that doesn't change.
What happens when you hit: http://theblackcat.dyndns.org ? Dyndns.org name server tells your ISP where to route theblackcat.dyndns.org requests, and the router sends the requests on port 80 to that webserver behind it. Now, what if I don't have only this main family website, but also a myriad of other little web sites, on that machine?
Let's say I have customer XYZ to set up and test on my home server before putting the application on his/her ISP. My router will get these, I know that from a simple nslookup:
$ nslookup xyz.theblackcat.dyndns.org
Non-authoritative answer:
xyz.theblackcat.dyndns.org canonical name = theblackcat.dyndns.org.
Name: theblackcat.dyndns.org
Address: aa.bb.cc.dd
So it will work, the requests will be routed to my dynamic address and come to my computer. I will need to set a xyz.theblackcat.dyndns.org as a name virtual host in apache.
I will need to:
1) Activate the name virtual host in Apache:
NameVirtualHost 192.168.0.2
2) set this new virtual host by name
ServerName xyz.theblackcat.dyndns.org
DocumentRoot /path/to/xyz/document/root
3) Restart Apache web server. Voila! Http://xyz.theblackcat.dyndns.org requests will go through the internet to my router (dyndns.org IP address resolution), from the router to the computer (static route + port forwarding), and from the computer to the right subdomain document root (apache listener and name virtual host).
You can have many Name Virtual Hosts listening to the same IP address (my G5 IP address) and Port (80) and still it will work! In the past I used to route customers to different ports (ex: http://theblackcat.dyndns.org:789), but this way is much more secure and cleaner.
You could carry your laptop over the world, with all these nice websites sleeping inside, and still have your dyndns.org name following you. Still be online. You might need to add some little dyndns.org client to send the new IP addresses in the case you're not behind a nice NAT router which performs it for you, to have your IP Address sent. Either way, easy and reliable. Be aware that if your laptop is off, unplugged, people will get nasty looking TCP errors. You might want to use a cheap provider an set a little dynamic page to test your web server and tell user "Sorry - please come back soon!" -- That's easy, another story I'll tell you another day...
No comments:
Post a Comment