Yes, it's possible, it just varies a little bit depending on whether you have a static or dynamic IP address from your ISP.
You can create either A or CNAME records for sub-domains so the process is fairly straight forward.
You (or your hosting company) will have created an A record for your domain pointing to the IP address of their infrastructure. They have likely also created an A record for the sub-domain www
as well using the same IP address, or they could have created a CNAME pointing to the domain.
To point some other sub-domain at your local machine, you would need to find your public IP address (a simple google search for what's my IP will get you your current IP) - if you have purchased a static IP from your ISP, then you can add a new A record to your name servers pointing at that IP address, and once you've configured your firewalls, routers and the server on your local machine appropriately you should be up and running.
If you do not have a static IP address, you will want to look into Dynamic DNS providers for a long term solution - some routers can talk to these services directly which takes the hassle out of managing this, some of the providers may have apps you can install to take care of it.
I have used the free service from No IP in the past to do just this:
- Create a free hostname with the Dynamic DNS provider pointing to your network
- Create a CNAME record for my sub-domain pointing to the free hostname
- Serve a website from my internal network, configured to respond on the sub-domain
Note that the web server didn't need to know about the free hostname, and my users never saw it directly - however it can be seen with an NSLookup - basically the browser asks for the IP address of sub.example.com
and is told: You need to look for skm1.ddns.net
which then leads to 123.456.789.012
, which is where the request is finally sent to.
Full Disclosure: I stopped using No IP purely because Synology offer their own equivalent with their DiskStation, but the principle is the same - I've got a sub-domain CNAME'd to the sub-domain on one of their domains, which is an A record with a short time-to-live and is updated by a job on the DiskStation whenever my IP address changes.