Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard DNS for only first level subdomain

I want to know how to set a wildcard DNS for only first level subdomain, example:

user.example.com     // valid
www.user.example.com // invalid

I have my BIND zone domain configured like this:

; example.com
$TTL 86400
@       IN      SOA     ns.example.com. domain.example.com. (
                                        2014021001 ; Serial
                                        28800      ; Refresh
                                        1800       ; Retry
                                        604800     ; Expire - 1 week
                                        86400 )    ; Minimum

                IN      NS      ns
                IN      NS      ns1

ns              IN      A       1.2.3.4 ; An IP
ns1             IN      A       1.2.3.4 ; An IP

@               IN      A       1.2.3.4 ; An IP
*.example.com   IN      A       1.2.3.4 ; An IP
www             IN      A       1.2.3.4 ; An IP

@               IN      TXT     "v=spf1 a mx -all"

And my Apache virtual host config is like this:

<VirtualHost 1.2.3.4:80>
  ServerAdmin [email protected]
  DocumentRoot /var/www/html/example.com
  ServerAlias www.example.com
  ServerName example.com
  ErrorLog logs/example.com-error_log
  CustomLog logs/example.com-access_log common
</VirtualHost>

<VirtualHost 1.2.3.4:80>
  ServerAdmin [email protected]
  DocumentRoot /var/www/html/apps.example.com
  ServerAlias *.example.com
  ServerName apps.example.com
  ErrorLog logs/apps.example.com-error_log
  CustomLog logs/apps.example.com-access_log common
</VirtualHost>

Please help!

like image 578
Fong-Wan Chau Avatar asked Nov 28 '25 06:11

Fong-Wan Chau


1 Answers

You can't do it in the DNS - a wildcard will match one or more DNS labels.

You may be able to do it in the Apache server, perhaps by using mod_rewrite to match on the supplied hostname and returning a 404 error if the hostname is invalid.

like image 115
Alnitak Avatar answered Nov 30 '25 00:11

Alnitak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!