Installing A FreeBSD 7.0 DNS Server With BIND - Page 4

You will then go back to the sysinstall main menu, you can then highlight X Exit Install and press [ENTER].

Remove the CD, highlight [YES] and press [ENTER].

After the reboot you can login with root to do administrative tasks, however if you are logging in via SSH you will need to login using the user you created and then switch to root using the su command.

Before installing 3rd party applications we need to configure FreeBSD to find the 3rd Party commands before the usual FreeBSD commands we will thus have to change the order of the default search path, we can do that by opening the .cshrc file:

cd /root
ee .cshrc

Then we will comment out (disable) the default path by adding a "#" at the beginning of the line so it looks like that:

#set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin)

Now we will add a new line for the new default search path:

set path = (/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin $HOME/bin)

Now save and exit the file, to save and exit just press escape then choose option a to leave and it will then ask you if you want to save or not.

Now logout [CTRL+D] and then login again, if you want to display the current search path use the following command:

echo $path

A good thing to do is to limit the SSH Access, to specify specific users add them to the sshd_config file, do to that open the file using easy editor:

ee /etc/ssh/sshd_config

Add the following line and remember to modify the users based on the users you want to allow, in the below example I'll allow user1 and user2 to access my server via SSH:

AllowUsers user1 user2

Save and Exit, then restart the ssh daemon using the command below:

/etc/rc.d/sshd restart


4 Configuring Static IP

If you have chosen DHCP during the installation, you can follow the following steps to configure a static IP, just remember to exclude then the server's IP from the DHCP so that it wont conflict with another network device.

We will edit the rc.conf file using the following command:

ee /etc/rc.conf

You should then see something like:


Please change your hostname if it's not correct, it should be your servers' FQDN.

Then we will modify the rest to look like that:

ifconfig_xlo="inet netmask"

As you can see above, we removed the word DHCP and typed our IP and netmask, and in a new line we added our router's IP.

Now save and exit.


5 Checking the Hosts and DNS IPs configuration

We need also to make sure that the hosts file and the resolve.conf file are configured correctly, so we will start by the hosts file:

ee /etc/hosts

It should look like this, please modify your domain name (e.g. tm.local), and your hostname (e.g. dnsfreebsd). based on your configuration:

::1  localhost  localhost  dnsfreebsd

Now save and exit.

We will now check the resolv.conf file:

ee /etc/resolv.conf

It should look like that, feel free to change based on your configuration, you should put the domain name at the top and then any DNS servers you have (your ISP ..etc) below after the word nameserver

domain tm.local


6 Updating the system

To make sure you are connected to the internet you can ping any website (e.g. if all good you can update and reboot the system using the following commands:

freebsd-update fetch
freebsd-update install

After rebooting you can display the release level using the following command:

uname -r


7 Configuring FreeBSD Ports Collection

The Ports Collection provides a centralized and simple way to install softwares, it is designed to be automated and relatively easy to use.

We will carry on the following steps also with the superuser.

First we will need to copy the ports-supfile to the /root to find it easily later:

cp /usr/share/examples/cvsup/ports-supfile /root

You need now to choose the nearest update server to your location, you can go to:

And choose the nearest server to you.

Share this page:

2 Comment(s)

Add comment


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


Great post.

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


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
#uname -a

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

#ping -c 3
#ee /root/ports-supfile

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

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

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

#> /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 netmask"

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:

Editing file named.conf:
#mcedit /var/named/etc/namedb/named.conf
 - delete localhost
 - set forwarders
 - add on the end of file:
 zone ""
 type master;
 file "master/";
 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/

Write into file:
    $TTL 3600 IN SOA
    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 IN NS

    ;Computer names IN A IN A

    www IN CNAME
    ww1 IN CNAME

    ;MX records IN MX 10

Then copy file
/var/named/etc/namedb/# cp working/

Change DNS servers on system:
#ee /etc/resolv.conf
Write into resolv.conf:

Set up config so BIND will start after reboot:
#ee /etc/rc.conf
Add this on the end:

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:

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

Open httpd.conf located in /usr/local/etc/apache22
#ee /usr/local/etc/apache22/httpd.conf
 - ServerAdmin   (put your e-mail address)
 - ServerName  (Remove comment add change address to

#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:

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

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:

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:

Log file of MySQL database

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
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();?>