Installing A FreeBSD 7.0 DNS Server With BIND - Page 6

Creating the Master forward lookup zone file

Remember to replace tm.local with your domain name, it must match what you have used before.

So we will create the file tm.local:

cd /var/named/etc/namedb/master
ee tm.local

Then we add the following:

$TTL    3600
tm.local.                     IN    SOA     dnsfreebsd.tm.local.   root.tm.local. (
                                                   1            ; Serial 
                                                   10800    ; Refresh
                                                   3600       ; Retry
                                                    604800  ; Expire
                                                   86400 )   ;Minimum TTL
; DNS Servers
tm.local.                     IN               NS   dnsfreebsd.tm.local.

; Computer names and records
dnsfreebsd.tm.local.     IN               A    192.168.0.2

; Aliases
www                          IN              CNAME    dnsfreebsd.tm.local.

; Mail MX Records
tm.local.                    IN     MX     10   dnsfreebsd.tm.local.

Feel free to modify based on what you want to do, you can add more aliases, A or MX records, and make sure to change your domain name above from tm.local to your domain name and make sure to add a "." after words, also change your hostname from dnsfreebsd to the hostname you are using.

root.tm.local is the e-mail address of the person responsible for the zone, here we use a "." instead of an "@" sign.

 

Creating the Master reverse lookup zone file

Now we will create a reverse lookup zone file for the forward one we created above using the following commands:

cd /var/named/etc/namedb/master
ee tm.local.rev

Then we we will add the below data to it, again feel free to modify based on your configuration:

$TTL    3600
0.168.192.in-addr.arpa.          IN    SOA    dnsfreebsd.tm.local.     root.tm.local. (
                                                   1            ; Serial
                                                    10800    ; Refresh
                                                   3600      ; Retry
                                                    604800   ; Expire
                                                    86400)   ; Minimum TTL
; DNS Servers
0.168.192.in-addr.arpa.          IN              NS    dnsfreebsd.tm.local.

; Computer IPs
100                                     IN               PTR    dnsfreebsd.tm.local.
100                                     IN               PTR    www.tm.local.

 

Testing your DNS Server

Now we are finished with configuration, we just need to start the service and test it.

First of all let's make sure that your server has it's own IP as the primary DNS server in the resolv.conf file.

Open the resolv.conf:

ee /etc/resolv.conf

and make sure you are using your DNS servers IP as the primary IP, my server's IP is 192.168.0.100 thus my resolv.conf looks like that with my IP at the first place:

domain tm.local
nameserver 192.168.0.100
nameserver 192.168.0.2

Save and Exit.

Configure named to start automatically at the boot time.

Open the rc.conf file in /etc:

ee /etc/rc.conf

We will then add the following line to it:

named_enable="YES"

Save and Exit.

Start the named service:

/etc/rc.d/named start

You can try to dig for google.com to make sure all good with your DNS server:

dig google.com

If you saw at the end (probably the 3rd line from down) something like this:

;; SERVER: 192.168.0.100#53(192.168.0.100)

So this means your DNS server (e.g. 192.168.0.100) was the one who answered the query.

You can try then to ping your A records if all give the expected reply then your DNS is working fine.

 

10 Sources and References

Share this page:

2 Comment(s)

Add comment

Comments

From: Anonymous at: 2009-02-13 10:44:12

Hi,

Great post.

This is a complementary article that explains howto setup IPv6 DNS zones with bind.

Cheers.

From: Anonymous at: 2012-01-24 09:35:36

Here is details on instalation php, bind, apache, mysql on freebsd:

After installation , run update:
#uname -a
#freebsd-update fetch
#freebsd-update install
#reboot
#uname -a

Port update:
#cp /usr/share/examples/cvsup/ports-supfile /root

#ping -c 3 cvsup6.freebsd.org
#ee /root/ports-supfile
(*default host=cvsup6.FreeBSD.org)

Starting update:
#csup -g -L 2 /root/ports-supfile

#whereis bash      //you can use: cd `whereis -q bash`    ; whereis -b bash    gives you path of binary
#cd /usr/ports/shells/bash
#make install
#hash
#rehash

#whereis portaudit
#cd /usr/ports/ports-mgmt/portaudit
#make install
#/usr/local/sbin/portaudit -Fda

#chsh -s /usr/local/bin/bash
#exit

#> /etc/motd     //write empty motd file, it displays on login

#whereis mc
#cd /usr/ports/misc/mc
#make install


Set static IP address:
#ee /etc/rc.conf
Add lines:
ifconfig_em0="inet 192.168.111.9 netmask 255.255.255.240"
defaultrouter="192.168.111.1"

Add user "user1" in group wheel so he can switch to root
#pw usermod student -G wheel



Installing BIND DNS service on FreeBSD:
#cd /usr/ports/dns/bind97/
#make config
#make install

Create file:
#cp /etc/make.conf /etc/make.conf.old
#ee /etc/make.conf
Add here this:
"NO_BIND = YES"

Editing file named.conf:
#mcedit /var/named/etc/namedb/named.conf
 - delete localhost 127.1.0.0
 - set forwarders
 - add on the end of file:
 zone "facebook.ba"
 {
 type master;
 file "master/facebook.ba";
 allow-transfer {localhost;};
 allow-update {key rndc-key;};
 }
 

Creating rndc key:
#rndc-confgen -a
#cd /var/named/etc/namedb
#cp named.conf named.conf.old
#cat rndc.key >> named.conf

Creating master file:
#cd /var/named/etc/namedb/
#mcedit facebook.ba

Write into facebook.ba file:
    $TTL 3600
    facebook.ba IN SOA server.facebook.ba root.facebook.ba
    (
    1 ; Serial ; Increment by one after every change
    10800 ; Refresh every hour
    3600 ; Retry every 15 minutes
    604800 ; Expire 1000 hours
    86400 ) ; Minimum 1 hour

    ;DNS servers
    facebook.ba IN NS server.facebook.ba.

    ;Computer names
    server.facebook.ba IN A 192.168.1.103
    komp.facebook.ba IN A 192.168.1.102

    ;Aliases
    www IN CNAME server.facebook.ba
    ww1 IN CNAME komp.facebook.ba

    ;MX records
    facebook.ba IN MX 10 mail.facebook.ba.

Then copy file facebook.ba:
/var/named/etc/namedb/# cp facebook.ba working/

Change DNS servers on system:
#ee /etc/resolv.conf
Write into resolv.conf:
domain facebook.ba
nameserver 192.168.1.103

Set up config so BIND will start after reboot:
#ee /etc/rc.conf
Add this on the end:
hostname="facebook.ba"
named_enable="YES"

Start BIND
#/etc/rc.d/named start

Create emty file: /var/named/etc/namedb/working/managed-keys.bind:
> working/managed-keys.bind

Test if everything works:
#dig www.facebook.ba
#dig www.google.ba



Installing APACHE service:
#cd /usr/ports/www/apache22
#make config
#make install   (On menu set all default, you can only desellect ipv6)

Configuration:
Open httpd.conf located in /usr/local/etc/apache22
#ee /usr/local/etc/apache22/httpd.conf
Change:
 - ServerAdmin you@example.com   (put your e-mail address)
 - ServerName www.exaple.com:80  (Remove comment add change address to www.facebok.ba:80)

Testing:
#apachectl configtest

Setting up  automatic start of Apache on system startup:
#ee /etc/rc.conf
Add on the end of file:
apache22_enabled = "YES"
apache22_http_accept_enable= "YES"

Restart apache server:
/usr/local/etc/rc.d/apache22 start

Webpage in this path:/usr/local/www/apache22/data/index.html

Log files are here:
/var/log/httpd-access.log
/var/log/httpd-error.log


Instalation of MySQL database:
#cd /usr/ports/databases/mysql55-server
#make -D BUILD_OPTIMIZED install
#hash



Configuration of MySQL database
#mysql_install_db --user=mysql

#mysql_safe &
#mysqladmin -u root password 'localpassword'

Copying existing configuration:
#cp /usr/local/share/mysql/my-medium.cnf /var/db/mysql/my.cnf

Restricting remote using of database, throught network:
ee /var/db/mysql/my.cnf
Remove comment on line 45 so it looks like this:skip-networking

Configuration for startup of MySQL:
#ee /etc/rc.conf
Add on the end:
mysql_enable="YES"

Restart MySQL to apply all changes:
#/usr/local/etc/rc.d/mysql-server restart

Showing databases:
#mysqlshow -p

Check permissions of TMP folder:
#chown root:wheel /tmp
#chmod 777 /tmp
#chmod = t /tmp

Loging on server
#mysql -u root -p

Showing databases and working with dthat database:
#mysql> show databases;

Creating dtabase:
#mysql> create database ins2007;

Adding user with full permissions on database:
#mysql> grant all on ins2007. to vt@localhost identified by 'password';

Adding userwith read permissions on base:
#mysql> grant select on ins2007.* to vt@localhost identified by 'password'

Adding user with customized permisions on database:
#mysql grant (choose between select,insert,update,delete,create,drop) on ins2007.* vt@localhost identified by 'password'

Removing users form dbase:
#mysql> revoke all privileges on ins2007.* from vt@localhost;

Removing users from MySQL servera:
#mysql> revoke all privileges, grant option from vt@localhost;
#mysql> drop user vt@localhost;

Erasing base:
mysql>drop database ins2007;

Showing privilegies for each user:
#mysql> show grants for vt@localhost;

Backup of all MySQL databases:
#mysqldump -u root -p --all-databases > /path/nameofbackup.sql

Backup only one database:
#mysqldump -u root -p --databases fitbaza > /path/iee nameofbackup.sql

Restore database:
#mysql -u root -p ins2007 < /path/nameofbackup.sql

Configuration file of MySQL database:
/var/db/mysql/my.cnf

Log file of MySQL database
/var/db/mysql/server.facebook.ba.err



Instalation of PHP
#cd /usr/ports/loang/php5
#make config ; make install
When menu appears choose Apache (Build  apache module), other leave default.

Edit Apache httpd.conf for php support:
#ee /usr/local/etc/apache22/httpd.conf
Change path of index.php:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
On the end add text:
AddType application/x-http-php .php
AddType application/x-http-php-source .phps

Copy configuration file php.ini:
#cd /usr/local/etc
#cp php.ini-recommended php.ini

Specificate session save.path in configuration of php:
#ee /usr/local/etc/php.ini
Remove comment and set path:
session.save_path = "/tmp"

Save and restart Apache
#/usr/local/etc/rc.d/apache22 restart

Testing php:
#ee /usr/local/www/apache22/data/phpinfo.php
Add this line:<?php phpinfo();?>