2

I have a domain like example.com, it is hosted on some web hosting service.

I read this article on how to convert your laptop/desktop into a server and host internet accessible website on it: part one and part two.

What I want is to add a sub-domain like sub-domain.example.com. For the sub-domain I want to redirect to my locally hosted site.

Is that possible? How can I achieve it?

1
  • 1
    It should just be a matter of pointing the subdomain at your IP (although you'd be better off using a dynamic DNS provider to prevent changing IP breaking your site)
    – jrtapsell
    Commented Jul 4, 2018 at 6:37

1 Answer 1

1

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:

  1. Create a free hostname with the Dynamic DNS provider pointing to your network
  2. Create a CNAME record for my sub-domain pointing to the free hostname
  3. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.