Reputation: 2961
A web app can potentially serve different pages, depending on the hostname that is requested by the browser, even if all hostnames are resolved to the same IP address.
For example, at
https://app.example.com
,
which resolves to
1.2.3.4
,
users will find the user interface
and at
https://admin.example.com
,
which also resolves to
1.2.3.4
,
awaits a dashboard
through which
only the app's owner can
administrate users and data
in the app.
In short,
we need to enter,
for example,
http://admin.app:8000/
in our browsers
and have that admin.app
resolve to 127.0.0.1
.
How can I configure custom hostname to IP address resolutions in my development environment?
Upvotes: 1
Views: 4668
Reputation: 299
(GNU/Linux)
Since all the major distributions are migrating (or already did) to systemd stack the proper place to implement wildcard support would be systemd-resolved: see https://github.com/systemd/systemd/issues/766 for details.
That would be the place to set custom overrides for DNS as well.
As for windows - its VM should just get DNS from host machine: it's to risky to run it on bare metal anyway.
Upvotes: 0
Reputation: 2961
Simply edit the hosts file. Its location depends on the OS. For example:
127.0.0.1 app.localhost
127.0.0.1 admin.localhost
On Windows you can use this nifty open source GUI for editing the hosts file: Hosts File Editor.
The hosts file does not support wildcards!
Since Ubuntu 12.04,
Ubuntu desktop comes with
a local DNS server,
which might not respect
the hosts file (/etc/hosts
).
So, for Ubuntu desktop, this answer
is best.
Upvotes: 1
Reputation: 2961
Acrylic DNS Proxy is easy to install and configure.
It can help us get hostnames with aliases quickly in Windows.
And it is open source.
hosts
file (via the start menu entry).1.2.3.4 >app
.127.0.0.1
.Upvotes: 0
Reputation: 2961
dnsmasq
Ubuntu Desktop's default networking configuration is
composed of NetworkManager and its slave dnsmasq
.
The slave dnsmasq
listens at 127.0.1.1
and /etc/resolv.conf
lists it as the only nameserver
.
This has some benefits.
What it means for this purpose is that we have a fully configurable DNS server, comfortably configured by default.
We can create
/etc/NetworkManager/dnsmasq.d/hosts.conf
and put in it whatever address
statements we'd like:
address=/admin.app/127.0.0.1
We can even use wildcards!
address=/.app/127.0.0.1
See the
dnsmasq
documentation
for details
(look for --address
).
Since dnsmasq
is started by the network-manager
service,
then I would assume that the following would restart it
so that new configuration would take effect:
$ service network-manager restart
But its init-script does not control slave dnsmasq.
Therefore the dnsmasq
process must be killed and then
the above command would have it start again.
And that is it!
Upvotes: 1
Reputation: 2961
In a virtual machine
127.0.0.1
and localhost
will not reach the host,
but the guest.
In VirtualBox, for example,
by default, the host can be reached
at 10.0.2.2
.
So, the guest VM's hosts file can look like
10.0.2.2 host
10.0.2.2 app.host
10.0.2.2 admin.host
If you're setting up
a proxy DNS nameserver
inside a virtual machine
(perhaps for wildcard support in Windows)
the upstream nameserver
is usually provided by the host.
In VirtualBox, it is 10.0.2.3
.
Upvotes: 0
Reputation: 2961
HOSTALIASES
FileThis would have been my preferred answer because it refrains from altering system configuration.
But:
It is a user specific host aliases file.
Notice that the format is not the same as the hosts
file.
In short, you create a file which contains host aliases.
For example
foo localhost
bar localhost
and place it at ~/.hosts
.
Then you set an environment variable
HOSTALIASES
with the path to the aliases file.
So, for this example
$ export HOSTALIASES=~/.hosts
Upvotes: 0