31 July 2013

Setup local DNS server to bind ALL subdomains

There is various situation where binding ALL subdomains to a specific applications (local or intranet) can be needed; for instance
working with Tomcat.

Let's say:
 - you want to create a main domain tomcatserver.test (IMPORTANT: avoid .local subdomain which is NOT compatible with some system)
 - bind all subdomains
 - your Internet Provider DNS are 212.27.40.240 and 212.27.40.241
 - computers are all on network 192.168.0/24
 - the @IP of the server computer is 192.168.0.2
 - your Tomcat applications can be reached via http://192.168.0.2:8080/MyApplication

Install and configure DNS server

 - install bind, for instance under GNU/Linux Fedora :
yum install bind

 - define configuration of bind (the following option allows use of only IPv4), editing file /etc/sysconfig/named
OPTIONS="-4"

 - edit the main configuration file /etc/named.conf, and update the following lines to allow access for all computers on network (adapt @IP)
       listen-on port 53 { 192.168.0.2; };
       allow-query     { 192.168.0/24; };

 - add this line at the end of the same file
include "/etc/named.conf.tomcatserver.test";

 - create the domain configuration file /etc/named.conf.tomcatserver.test
zone "tomcatserver.test" IN {
type master;
file "/etc/named.conf.tomcatserver.test.zone";
};

 - create the zone file /etc/named.conf.tomcatserver.local.zone (adapt @IP of your server and DNS)
$TTL 3H
@       IN SOA  @ ns.tomcatserver.test. (
                                        9       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
* IN A 192.168.0.2
@ IN NS 212.27.40.240
@ IN NS 212.27.40.241

@ IN A 192.168.0.2
www IN A 192.168.0.2
* IN A 192.168.0.2

 - you can add several others information like MX (Mail eXchange) ...

 - register your local DNS server adding this line at begining of /etc/resolv.conf (adapt @IP)
nameserver 192.168.0.2

 - [re]start the DNS server
service named restart

Update rules of your Firewall

You must update your Firewall to allow computers of the network to use this DNS server (port 53).

Added a new VirtualHost

Eventually, create a VirtualHost with Proxy mod allowing to 'redirect' request from just created domain, to the Tomcat application.
 - create the file /etc/httpd/conf.d/myTomcatApplication.conf

    ServerName tomcatserver.test
    ServerAlias *.tomcatserver.test
    ProxyRequests Off
    ProxyPreserveHost On
   
        Order deny,allow
        Allow from all
   
    ProxyPass / http://192.168.0.2:8080/MyApplication/
    ProxyPassReverse / http://192.168.0.2:8080/MyApplication/


 - restart your HTTP server
service httpd restart


That's it !
Any computers on local network can now access tomcatserver.test and any *.tomcatserver.test subdomains to reach your Tomcat application, usually available under http://192.168.0.2:8080/MyApplication/.




No comments:

Post a Comment

Thank you for your visit, let's share your point of view: