To make Unbound (a validating, recursive, and caching DNS resolver) alias a hostname on Debian, you typically want to create a DNS alias (also known as a CNAME record) or a host override (for local resolution). Here’s how you can do it:
Open the Unbound configuration file for editing:
bashsudo nano /etc/unbound/unbound.conf.d/aliases.conf
If the file doesn’t exist, create it.
To alias a hostname (e.g., alias.example.com to real.example.com), add a local-zone and local-data entry:
iniserver: # Alias 'alias.example.com' to 'real.example.com' local-zone: "alias.example.com" redirect local-data: "alias.example.com. IN CNAME real.example.com."
local-zone: "alias.example.com" redirect
This tells Unbound to treat alias.example.com as a local zone and redirect queries for it.local-data: "alias.example.com. IN CNAME real.example.com."
This creates a CNAME record, aliasing alias.example.com to real.example.com.After saving the file, restart Unbound to apply the changes:
bashsudo systemctl restart unbound
Test the alias using dig or nslookup:
bashdig alias.example.com @127.0.0.1
or
bashnslookup alias.example.com 127.0.0.1
You should see the alias resolving to the target hostname.
/etc/hosts for Local ResolutionIf you only need the alias to work locally (not for other machines querying your Unbound server), you can also add an entry to /etc/hosts:
bashsudo nano /etc/hosts
Add a line like this:
plaintext192.0.2.1 alias.example.com
(Replace 192.0.2.1 with the actual IP of real.example.com.)
/etc/hosts is simpler.This Chat is read-only. Login to resume chatting.
server:
# Alias 'alias.example.com' to 'real.example.com'
local-zone: "alias.example.com" redirect
local-data: "alias.example.com. IN CNAME real.example.com."