I have done this because as a web developer, I like to work on sites on my home server then upload the site to the final hosting company after it's working. So, to allow the client to see and approve changes, I got a domain from dynDNS (dyn.com) for $20/year. There are similar systems for free, and dynDNS used to have a free account, but I don't think they do anymore. But I chose the dynDNS Pro, because $20/year is pretty cheap, and you get multiple domain names and wildcard domains.
What it Does
This service works by giving you a choice of existing domain names they own, such as yourname.homelinux.net, etc. For example, you can choose one called somename.homelinux.net, and then you can instantly create a unique site called xxx.somename.homelinux.net without registering it, and in Apache, set up a domain with that name. That's all it takes to create a new domain. You can also register other domains. There may be a more premium service that allows you to use your existing domain name, and have it hosted with them, but I don't need that.
How it Works
They have an app that updates your dynamic IP periodically. So, you have a constant domain name, but the IP it points to can change.
How to Set Up Apache on Ubuntu
Apache can take a domain name and use it to access a local website in any given directory using Virtual Hosts. The IP address doesn't matter, and you can have any number of virtual hosts using the same IP address; it's the name that matters, not the address.
This done by making an entry in a configuration file, at
/etc/apache2/sites-enabled/000-default. I'm assuming the default configuration; I think you could have more than one of these files, but I haven't done this.
In order for this to work, you need to have a module enabled called rewrite.load. This module is in
/etc/apache2/mods-available, and to use it, you would create a symbolic link in the directory
/etc/apache2/mods-enabled (from the mods-enabled directory, enter "
ln -s ../mods-available/rewrite.load").
OK, once this is done, then for any domain name you want to resolve on your local system, you create a multi-line entry in the configuration file (000-default). I like examples better than directions, so here is an example:
Setup of /etc/apache2/sites-enabled/000-default
Assume you have a local website, and you use dynDNS with a name like mycoolsite.homelinux.com. Further assume that the site's location is in /var/www/mycoolsite (it can be anywhere, including your home directory). Then, the following entry at the end of your configuration file would make this work (assumes port 80, the conventional web port):
Options Indexes FollowSymLinks MultiViews
allow from all
Note that this is not the only set of parameters that work. The Directory section is not needed if you don't need to change anything from the defaults, but I always just include it, and it's been a while since I figured out exactly why. But it always works, so I leave it be.
This same setup can be used to make a "fake" development site on localhost, if you make an entry in your hosts file on any machine that will access it, assigning a name to the IP (either localhost, or the IP address of the server on the LAN). You can have a number of these aliases in your hosts file, all with the same IP.
I don't fully understand what you are asking for the second part of your question. If you want to further elaborate, I'll try to help. It may be that the method I suggested isn't what you are looking for. If not, I'm sorry. Let me know if you have questions.