Hacker’s Diary

Avatar

My Knowledge Database

[HowTo] Bind9+MySQL on Debian

Tired of editing Bind zone files? Or you want to create UI for your clients, so they can edit their zones? It can’t be easier, than when you have your zones in MySQL database.

Here I will explain how to install Bind with MySQL database support. After patching, Bind will be able to use both, MySQL tables and zone files.

Installing packages and getting sources

Get MySQL BIND SDB driver from http://mysql-bind.sourceforge.net/

If you don’t have a Bind server yet, it would be nice to install it. This will create startup scripts, sample configs, etc.

apt-get install bind

Now set up all other packages need:

apt-get install mysql-server-5.0 mysql-client libmysql++-dev dpkg-dev

Now, get source of your existing Bind package (the current version is bind9-9.3.4):

apt-get source bind

Untar both packages, bind9_9.3.4.orig.tar.gz and mysql-bind.tar.gz

There is already a README with mysql-bind package, but I’ll explain here as well.

Copy file mysqldb.c from mysql-bind package to “bind9-9.3.4/bin/named/mysqldb.c” and
mysqldb.h to “bind9-9.3.4/bin/named/include/named/mysqldb.h

Patching Bind source files

Edit: bind9-9.3.4/bin/named/Makefile.in

Under comment “# Add database drivers here.” set these:

DBDRIVER_OBJS = mysqldb.@O@
DBDRIVER_SRCS = mysqldb.c
DBDRIVER_INCLUDES = -I’/usr/include/mysql’
DBDRIVER_LIBS = -L’/usr/lib/mysql’ -lmysqlclient

Where:
DBDRIVER_INCLUES is output of “mysql_config –cflags
DBDDRIVER_LIBS is output of “mysql_config –libs

Edit: bind9-9.3.4/bin/named/main.c

Add “#include <named/mysqldb.h>” in the beginning of the file, right after this comment “* Include header files for database drivers here.“.

Add “mysqldb_init();” right before “ns_server_create(some params);” and “mysqldb_clear();” after “ns_server_destroy(some params);“.
You’ll see comments like “* Add calls to register/unregister sdb drivers here.

Compiling Bind

Now go to bind9-9.3.4 and configure.

“sysconfdir”, “prefix” and “localstatedir” should much your current configuration. If you installed bind via APT, then these should be the right ones:

./configure –sysconfdir=/etc/bind –prefix=/usr –localstatedir=/var/run/bind
make
make install

Now if you restart Bind (/etc/init.d/bind9 restart), it should run without problems.

Creating database and inserting sample data

mysql> create database bind;

mysql> use bind;

I will create a subzone of hackersdiary.com, test.hackersdiary.com

mysql> CREATE TABLE test_hackersdiary_com (
name varchar(255) default NULL,
ttl int(11) default NULL,
rdtype varchar(255) default NULL,
rdata varchar(255) default NULL
) TYPE=MyISAM;

mysql> INSERT INTO test_hackersdiary_com VALUES (’test.hackersdiary.com’, 3600, ‘SOA’, ‘ns.hackersdiary.com. tom.hackersdiary.com. 200902051 28800 7200 86400 28800′);
mysql> INSERT INTO test_hackersdiary_com VALUES (’test.hackersdiary.com’, 3600, ‘NS’, ‘ns.hackersdiary.com.’);
mysql> INSERT INTO test_hackersdiary_com VALUES (’test.hackersdiary.com’, 3600, ‘NS’, ‘ns2.hackersdiary.com.’);
mysql> INSERT INTO test_hackersdiary_com VALUES (’test.hackersdiary.com’, 3600, ‘MX’, ‘10 mail.test.hackersdiary.com.’);
mysql> INSERT INTO test_hackersdiary_com VALUES (’mail.test.hackersdiary.com’, 3600, ‘A’, ‘127.0.0.1′);

Now setup zone in “/etc/bind/named.conf.local

zone “test.hackersdiary.com” {
type master;
database “mysqldb bind test_hackersdiary_com localhost binduser bindpassword”;
};

Restart Bind (/etc/init.d/bind9 restart)

Testing zone

Now ask your nameserver to resolve mail.test.hackersdiary.com “dig mail.test.hackersdiary.com @ns.hackersdiary.com

You should get:
;; ANSWER SECTION:
mail.test.hackersdiary.com.     3600    IN      A       127.0.0.1

Now get PhpMyAdmin or create your own UI for zone editing. There is one ready to use dnsSQLpanel, but I haven’t tested it.

Comments? Problems? You’re welcome.

Bookmark and Share

[HowTo] Change Windows Remote Desktop port

1. Click Start, click Run, type Regedit.exe, and then click OK.
2. Locate the following key in the registry:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp\PortNumber
3. On the Edit menu, click Modify, then switch Base to Decimal and enter your desired port number.

Restart your computer, to activate changes.

Bookmark and Share

[HowTo] Virtual Machines on Debian using XEN

This solution assumes you have already installed Debian Linux with minimum base system.

This solution is made for amd64 system. But others should be the same, just find the correct package for you system.

Setup

First install SSH, so it will be a lot easier to copy/paste commands in console

apt-get install ssh

Remove packages we don’t need

apt-get remove exim4 exim4-base lpr nfs-common portmap pidentd pcmcia-cs pppoe pppoeconf ppp pppconfig
apt-get install screen debootstrap iproute python python-twisted-core python-twisted-conch bridge-utils

XEN related packages

apt-get install xen-linux-system-2.6.18-6-xen-amd64
apt-get install xen-tools

If you wish to use XFS file system, you also need to install xfsprogs

apt-get install xfsprogs

Creating Virtual Machines

The best way of creating up virtual machines is using hard drives LVM volume, thus way you can easly increase partition size of partition where VM is.

Creating virtual machine using LVM volume vs0, and ext3 filesystem. VM will be running minimum base install of Debian Linux

xen-create-image –hostname=vm1.hackersdiary.com –size=4Gb –swap=512Mb –ide \
–ip=10.0.0.119 –netmask=255.255.255.0 –gateway=10.0.0.1 –force \
–lvm=vs0 –memory=512Mb –arch=amd64 –fs=ext3 –kernel=/boot/vmlinuz-2.6.18-6-xen-amd64 \
–debootstrap –dist=etch –mirror=http://ftp.ee.debian.org/debian/ –passwd \
–initrd=/boot/initrd.img-2.6.18-6-xen-amd64

This will create a 4Gb root partition, and 512Mb swap for VM. After the installation of base system, you will be required to input root password for your newly created VM.

To create XFS filesystem on VM, replace the –fs=ext3 with –fs=xfs
To use image files instead of LVM volumes replace –lvm=vs0 with –dir=/vm/images

Make VM to start automatically on boot

ln -s /etc/xen/vm1.hackersdiary.com.cfg /etc/xen/auto

Starting up VM manually

xm create -c /etc/xen/vm1.hackersdiary.com.cfg

To leave VM’s shell, type CTRL+] if you are at the console, or CTRL+5 if you’re connected to main debian using ssh

Shutting down VM

xm shutdown vm1.hackersdiary.com

Also awailable commands

xm reboot vm1.hackersdiary.com
xm list


How to increase VM’s partition size (Only if using LVM)

XFS Filesystem

lvextend -L+10G /dev/vs0/vm1.hackersdiary.com-disk
xm shutdown vm1.hackersdiary.com
mount /dev/vs0/vm1.hackersdiary.com-disk /vm/base
xfs_growfs /vm/base
umount /vm/base
xm create -c /etc/xen/vm1.hackersdiary.com.cfg

EXT3 Filesystem

lvextend -L+10G /dev/vs0/vm1.hackersdiary.com-disk
xm shutdown vm1.hackersdiary.com
resize2fs /dev/vs0/vm1.hackersdiary.com-disk
e2fsck -f /dev/vs0/vm1.hackersdiary.com-disk
xm create -c /etc/xen/vm1.hackersdiary.com.cfg

Comments? Problems? You’re welcome.

Bookmark and Share

,

Protect yourself

FREE Online Scanner - Detect more than 3 million threats

Some useful ads

Before you go

Going so soon? May these links be a guide to web enlightenment. Schwing!