It gets kind of complicated and @closetnoc does a good job of simplifying the process but I will try to expand it into detail here. For the purpose of this example I will use the following givens...
Domain: domain.com
Registrar: GoDaddy
Web Server: gator15.hostgator.com
When you register a domain name you do this through a domain registrar who acts as a seller domain names on behalf of the root domains register (Verisign for .com domains). Once this has happened your registration information, while having been done through GoDaddy, is actually held both by GoDaddy as well as by Verisign.
Now you choose a DNS provider. Now most registrars provide DNS hosting as part of their services or you can choose to go with a separate provider. In this example I will say that the DNS is being provided by AWS. You set up a new DNS service through AWS for hosting your DNS records. At the top of the zone information will be the SOA record (statement of authority). This record states the DNS servers which are the authoratative name servers for your domain name. These also happen to be the name servers you give to your registrar to go down as your name servers for your domain name.
So far what we have done is created a new domain name and configured it to point to the DNS host we want so we can configure out DNS settings, but now we want to point it to our web server. We have already created a web hosting service with HostGator on server gator15.hostgator.com and it has been configured to respond to both example.com
as well as www.example.com
. We go into our DNS hosts admin panel (AWS) and create a new A record named example.com.
and point it to the IP address we have been given by HostGator. We create a new CNAME record name www
and point to example.com
.
At this point we have done everything that needs to be done from registering a domain to pointing it to our website and getting it all working.
What you mention in your post about dozens of people creating their own web space with your domain name is true, anyone can as there is no restriction on what you name a web space when setting up a site but the fact is no one will be able to access it. In order to get to the web server it first has to go through checking the name servers for the domain at the registrar, then connect to the name servers and check what IP address is associated with the DNS address requested, then direct the browser to that IP address. It is a fairly safe assumption that if someone has been able to change the DNS zone file or the name server settings (not taking into account hacking those providers) then they have the authority to say where the web site is hosted and state that a particular server is the server that should be running the site.