Building DNS server (Bind9) and Mail server (Postfix) In Ubuntu


The first step to build a DNS server  you must install bind9 first. to install and configure bind9 we follow these steps:

$ sudo su
$ apt-get install bind9

for security reasons we run from the chroot bind9, and the steps are as follows:
 stop bind services  by type :

$ /etc/init.d/bind9 stop




edit file /etc/default/bind9 so that the daemon will run unprvilage user 'bind', chroot to /var/lib named. Change the line:

opts = "-u bind"
OPTS="-u bind -t /var/lib/named":
OPTIONS="-u bind -t /var/lib/named"

by type :

$ gedit /etc/default/bind9

make a directory in the /var/lib, by type :

$ mkdir -p /var/lib/named/etc
$ mkdir /var/lib/named/dev
$ mkdir -p /var/lib/named/var/cache/bind
$ mkdir -p /var/lib/named/var/run/bind/run


Then move the configuration from /etc to  /var/lib/named/etc, by type :

 $ mv /etc/bind /var/lib/named/etc

create a link to the new directory configuration from the old directory by using the following command:

$ n -s /var/lib/named/etc/bind /etc/bind 

Make null and random devices, and create a right of ownership by type :

$mknod /var/lib/named/dev/null c 1 3
$mknod /var/lib/named/dev/random c 1 8
$chmod 666 /var/lib/named/dev/null /var/lib/named/dev/random
$chown -R bind:bind /var/lib/named/var/*
$chown -R bind:bind /var/lib/named/etc/bind


edit the startup script /etc/init.d/sysklogd so that we can get a message from the logs. Change the line: syslogd="----"  to:  SYSLOGD="-a /var/lib/named/dev/log" by type :


$ gedit /etc/init.d/sysklogd
----------------
#! /bin/sh
# /etc/init.d/sysklogd: start the system log daemon.

PATH=/bin:/usr/bin:/sbin:/usr/sbin

pidfile=/var/run/syslogd.pid
binpath=/sbin/syslogd

test -x $binpath || exit 0

# Options for start/restart the daemons
# For remote UDP logging use SYSLOGD="-r"
#
SYSLOGD="-a /var/lib/named/dev/log"

create_xconsole()
{
if [ ! -e /dev/xconsole ]; then
mknod -m 640 /dev/xconsole p
else
chmod 0640 /dev/xconsole
fi
chown root:adm /dev/xconsole
}

running()
{
# No pidfile, probably no daemon present
#
if [ ! -f $pidfile ]
then
return 1
fi

pid=`cat $pidfile`

# No pid, probably no daemon present
#
if [ -z "$pid" ]
then
return 1
fi

if [ ! -d /proc/$pid ]
then
return 1
fi

cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1`

# No syslogd?
#
if [ "$cmd" != "$binpath" ]
then
return 1
fi

return 0
}
case "$1" in
start)
echo -n "Starting system log daemon: syslogd"
create_xconsole
start-stop-daemon --start --quiet --exec $binpath -- $SYSLOGD
echo "."
;;
stop)
echo -n "Stopping system log daemon: syslogd"
start-stop-daemon --stop --quiet --exec $binpath --pidfile $pidfile
echo "."
;;
reload|force-reload)
echo -n "Reloading system log daemon: syslogd"
start-stop-daemon --stop --quiet --signal 1 --exec $binpath --pidfile $pidfile
echo "."
;;
restart)
echo -n "Restarting system log daemon: syslogd"
start-stop-daemon --stop --quiet --exec $binpath --pidfile $pidfile
sleep 1
start-stop-daemon --start --quiet --exec $binpath -- $SYSLOGD
echo "."
;;
reload-or-restart)
if running
then
echo -n "Reloading system log daemon: syslogd"
start-stop-daemon --stop --quiet --signal 1 --exec $binpath --pidfile $pidfile
else
echo -n "Restarting system log daemon: syslogd"
start-stop-daemon --start --quiet --exec $binpath -- $SYSLOGD
fi
echo "."
;;
88888888 *)
echo "Usage: /etc/init.d/sysklogd {start|stop|reload|restart|force-reload|reload-or-restart}"
exit 1
esac

exit 0
--------------
 Restart daemon logging then start bind9 by type :

$ etc/init.d/sysklogd restart 
$ /etc/init.d/bind9 start  

Building DNS Server
Before building mailserver we must build a DNS server.

Note:

- Local IP in use: 192.168.1.172
- Domain machine: exxx
- DNS servers: exxx.example.com

Create a file in the directory /etc/bind/:

$ touch exxx.zone exxx.rev
$ gedit /etc/bind/named.conf


add following line
--------
zone "example.com" {
type master;
file "/etc/bind/exxx.zone";
};//
zone "4.168.192.in-addr.arpa" {
type master;
file "/etc/bind/exxx.rev";
};//
---------
$ gedit /etc/bind/exxx.zone

add following line :
-----------
$TTL 1D
@ IN SOA example.com. root.example.com. (
34; serial
23M ; refresh
9H ; retry
7D ; expire
1D) ; minimum
;
@ IN NS example.com.
@ IN MX 10 mail.example.com.
exxx IN A 192.168.4.206
www IN CNAME exxx
ftp IN CNAME exxx
mail IN CNAME exxx
------------
 $ gedit /etc/bind/exxx.rev

-----
$TTL 1D
@ IN SOA example.com. root.example.com.
43; serial
15M ; refresh
3H ; retry
1W ; expire
1D ) ; minimum
;
@ IN NS profff.asseifff.net.
206 IN PTR profff.asseifff.net.
-----

Restart bind9 by type :

$ /etc/init.d/bind9 restart

To ensure avoid trouble, setting:

$ gedit /etc/resolv.conf

ameserver 192.168.1.172

$ gedit /etc/hosts

192.168.4.206 profff.asseifff.net profff

$ gedit /etc/hostname

exxx

$ /bin/hostname -F /etc/hostname    //(to move from /etc/hostname to /bin/hostname)
 
For testing use the command:

$ host exxx.example.com

If show:
exxx.example.com A 192.168.1.172 (the DNS server configuration is complete)

Install and Configuration Mail Server (postfix):


$ apt-get install postfix
$ apt-get install ipopd

$ gedit  /etc/postfix/main.cf

Mynetwork = 192.168.1.0/24
Myhostname = mail.example.com
Inet_interface = all
Mydomain = example.com


$ postfix restart
$ postfix start
$ adduser minez
$ passwd 1234root

$ netstat -tapn
$ telnet 192.168.1.133 25 

Output :


echo........
mail from:root@mail.example.com
rcpt to:minez@mail.example.com

$ gedit /var/mail/(username)

If you have  message sent was found on the file /var/mail/(username) then the mail server has been successfully executed.....!!
its so Confused, haha Happy Testing.......!!

No comments:

Post a Comment

Please Comment...!!