0

I'm trying to create DNS for wildcard subdomains that run on localhost.

It's not working. The main domain is fine but the sub domains are pointing to an external server instead.

Here's what I have:

In /etc/named.conf:

zone "typeflex" IN {
    type master;
    file "/var/named/typeflex.zone";
    allow-update { none; };
};

In /var/named/typeflex.zone:

$TTL    86400;
@   IN SOA typeflex.com.    hostmaster.typeflex.com. (
    20170101        ; serial
    3h              ; refresh
    1h              ; retry
    1w              ; expiry
    1d              ; minimum
    )

    IN  NS  typeflex.com.
    IN  A   127.0.0.1

@                       IN A            127.0.0.1
*                       IN A            127.0.0.1
*.typeflex.com.         IN A            127.0.0.1
www                     IN CNAME        typeflex.com.
Asa Carter
  • 239
  • 1
  • 3
  • 14

2 Answers2

2

Your zone is not for typeflex.com. but for typeflex. TLD. The typeflex.com is working because /etc/hosts overrides the DNS A record for it. For every subdomain, the authoritative DNS server is used instead.

If you have localhost as your recursive DNS server, you don't need to have anything related in your /etc/hosts; just create a authoritative zone for typeflex.com. and add:

$ORIGIN typeflex.com.
@ IN SOA ...
@ IN A 127.0.0.1
* IN A 127.0.0.1
Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
  • I've updated my example and removed the hosts entry but it's still directing to the external site. Do I need a reverse zone file and is there anything else missing? – Asa Carter Jun 13 '17 at 22:06
1

Change zone "typeflex" IN { to zone "typeflex.com" IN { and make sure you run rndc reload to make changes active.

Then make sure your /etc/resolv.conf uses:

nameserver 127.0.0.1

... and not any other nameservers.

Also make sure your bind configuration allows for recursive lookups from loopback (127.0.0.1).

Alexander K
  • 336
  • 1
  • 5