
|
View Full Version : Automating Subdomains and A-Records...
owenwilson 01-09-2009, 01:11 AM Hey guys, finally registered after being a frequent browser of this wonderful forum.
I'm looking to start a service that acts similar to what's found here: dyndns.com/services/dns/dyndns/
I want to make it so that an end-user can type in their subdomain, choose a domain, then enter their IP that they want redirected, and bam!
I have some knowledge of programming, and much more on game servers (though that doesn't really matter). Could someone enlighten me on what I would need as far as hosting goes (VPS, reseller?), and how I would go about automating the process?
Thanks a lot!
ThatScriptGuy 01-09-2009, 01:31 AM You can accomplish this in several ways.
One way is to directly add a DNS zone when a user signs up for your service.
Another way (And the preferred method, I'm sure) is to use wildcard subdomains (http://steinsoft.net/index.php?site=programming/articles/apachewildcarddomain) coupled with a database of the subdomains and their corresponding IP addresses.
Simply put - You set up Apache to process wildcard subdomains for your domain name. Now, anytime a user visits theirname.yourdomain.com, your custom script (PHP, Perl, whatever) will take over and redirect the browser to where it's supposed to go by pulling the IP for the subdomain in question.
It's actually extremely simple to do once you understand it.
owenwilson 01-09-2009, 02:37 AM Thanks for the reply! It doesn't seem too complicated, I just need to understand it a bit better (I have the gist of it, I believe). Much thanks!
Edit: Maybe I'm a bit lost, but I don't think you fully understood my question (or maybe I just don't fully understand what you said :P). I want to be able to access [craig].domain.com and have it redirect to [craig's ip]. I think A-records?
Red Squirrel 01-09-2009, 03:40 AM oh so you want to basically let users use your dns server and manage their subdomains correct?
I don't know of any scripts that do it but I'm sure some exist. It's ironic as I've been working on a control panel and it will have that feature in it. Users will be able to add/edit zones. But don't hold your breath, still a lot to do before I release the first beta. ;)
I run my DNS off a MySQL DB so I can update it through my own CP. I've been running it this way for at least 3-4 years when it was a patch in bind, and it has since become incorporated into bind. It's stable and fast.
You can read about it @ http://bind-dlz.sourceforge.net/
Sidenote: This makes it even easier to setup slaves, as you can replicate the MySQL DB so there's never any delay in your requests.
ThatScriptGuy 01-09-2009, 02:00 PM Edit: Maybe I'm a bit lost, but I don't think you fully understood my question (or maybe I just don't fully understand what you said :P). I want to be able to access [craig].domain.com and have it redirect to [craig's ip]. I think A-records?
No, you just didn't understand me. Here is what I'm saying -
You have a signup form in PHP that stores subdomains and their IP addresses in a MySQL database - For simplicity sake, let's call the fields "subdomain" and "ip"
Now, you set up a wildcard DNS entry to point *.yourdomain.com to your PHP script.
PHP script is gets called when someone visits craig.yourdomain.com, and looks up in the database "craig" and directs the user to "craig"'s corresponding IP address.
Trust me - This is the PREFERRED way to do this, as is proven by the hundreds of affiliate scripts that use wildcard DNS for their subdomains.
http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html
That link explains EXACTLY how to do what I'm describing. If you do it by directly editing your DNS zones, you're going to end up with a ridiculously huge zone...
owenwilson 01-09-2009, 03:38 PM Thanks a million, you're amazing!
owenwilson 01-09-2009, 03:48 PM It looks as if this (wiredstudios), has me redirect everything to one IP address based off of wildcarded subdomains. Here's the exact scenario I'm using:
I'm going to allow people to create a subdomain such as craig.domain.com, which will redirect (not using the HTTP protocol because it's games not web!) the end-user when they connect to the server in-game.
I do not know their IP yet, so it has to be added in correspondence to what their subdomain is.
ThatScriptGuy 01-09-2009, 03:52 PM You're going to have to extrapolate on the links I'm giving you. The wiredstudios link tells you how to set up wildcard DNS and how to pull the subdomain from the URL. So now it's up to you to take that subdomain and look up the IP address from your database and do what you want with it.
The code on wiredstudios very clearly explains how to trap the subdomain using PHP, and then very clearly says that once you've trapped the subdomain, YOU CAN DO WHAT YOU WANT WITH IT. In your case, you will take that trapped subdomain and look up the corresponding IP address in your database.
owenwilson 01-09-2009, 03:58 PM You're going to have to extrapolate on the links I'm giving you. The wiredstudios link tells you how to set up wildcard DNS and how to pull the subdomain from the URL. So now it's up to you to take that subdomain and look up the IP address from your database and do what you want with it.
The code on wiredstudios very clearly explains how to trap the subdomain using PHP, and then very clearly says that once you've trapped the subdomain, YOU CAN DO WHAT YOU WANT WITH IT. In your case, you will take that trapped subdomain and look up the corresponding IP address in your database.
I just got it now! Thanks for all your time, I really appreciate it.
ThatScriptGuy 01-10-2009, 01:38 AM Not a problem. Just come back if you need any more help.
kcackler,
Your method is for HTTP traffic, which will very likely do nothing for allowing someone to connect to 'gameserver.domain.com' within an actual game. Unless games are now checking HTTP after the game server port is closed :)
Plutost 01-10-2009, 09:20 AM I knew a Script, like co.cc website, But I dont remember its name. You can start a service like Giving Subdomains :) with that script
Adam-AEC 01-10-2009, 01:45 PM A quick browse of freshmeat returned these:
http://freshmeat.net/projects/ned/
http://freshmeat.net/projects/sddns/
http://freshmeat.net/projects/proutdns/
http://freshmeat.net/projects/tinydyn/
http://freshmeat.net/projects/diydynamicdns/
http://freshmeat.net/projects/gnudip2/
http://freshmeat.net/projects/tinyddns/
I don't think you'll find anything that will work off the shelf. Something like this is fairly easy to implement from scratch, either using powerdns or bind-dlz.
|