I have a website where users can sign up and create a site. They can access their website by typing username.example.com.

However, I would like to add to this the ability to buy a domain name and point it to username.example.com

so example.com/guestbook.html would translate to username.example.com/guestbook.html (external domain and associated user are mapped in the database)

Do I need my own DNS server for this or is there a simpler solution? Also, how should the database lookup be performed for this to work?