You can buy a domain and hosting from a domain name registrar, for example godaddy.com
After the purchase you will need to configure the DNS settings in the control panel on the site where it is registered.
First of all, you must specify to which IP address it is associated. To do this, add an A-record that will redirect requests to the domain to the specified IP. If you do not know which IP to specify, then you probably also need to order hosting for the site, after which you will have the IP address of the hosting.
An example of adding an A-record:
Data: IP Address
We also add an A-record for the www subdomain (further we configure on the web server so that the website opens through it too, or there was a redirect to the main domain):
Data: IP Address
In a similar way, you can add as many subdomains as you like and link them to any IP addresses.
TTL parameter determines the time during which the record will be stored in the cache of other DNS servers, when you first set up, you can specify 30 minutes, for example, and when everything is configured, you can increase it, but when you move the site to another hosting, you will have to change to A-record the IP address and wait until it is updated in the cache of other DNS, small values are also not desirable to set, for example, if the DNS server stops working, such cases may be in any large companies, the data will remain in the cache of other DNS and the site will work for users lei who recently opened it.
This completes the basic setup. After changing the DNS records, you will have to wait some time for the changes to take effect, usually from a few minutes to one day, until the DNS server cache is updated.
If necessary, you can add NS-records, and start your DNS server.
See below my articles:
How to add MX record
How to configure SPF records
Installing and Configuring DNS Server BIND9