Tuesday, March 31, 2015

[Quick Install]: How To Install PowerDNS On Ubuntu 14.04 & CentOS

How To Install PowerDNS On Ubuntu 14.04

powerdns
PowerDNS is an open source, high performance, and DNS server. It runs on many GNU/Linux, Unix, and Mac OS X systems. It is written using C++, and released under the GPLv2. It uses popular Databases, such as MySQL, MariaDB, PostgreSQL, and Oracle etc., to read the Zone files and records.
In this tutorial, let us see how to install PowerDNS on Ubuntu 14.04. Also, the same steps will work on Debian and it’s derivatives.

Install PowerDNS On Ubuntu

Scenario:

Operating system: Ubuntu 14.04 LTS server
IP Address: 192.168.1.250/24
Hostname: server.unixmen.local

Update your system:

First of all, update your system:
sudo apt-get update && sudo apt-get upgrade -y

Setup MySQL:

sudo apt-get install mysql-server mysql-client
During installation you’ll be asked to set MySQL root user password. While it’s not mandatory, It is highly recommended.
sk@server: ~_001
Re-enter the password.
sk@server: ~_002
Now, edit /etc/mysql/my.cnf to make MySQL to listen all interfaces.
sudo vi /etc/mysql/my.cnf
Find the following line, and comment it out.
[...]
#bind-address           = 127.0.0.1
[...]
Save and close the file. Restart MySQL service.
sudo service mysql restart
We completed the installation now. Next, we will Install PowerDNS.

Install PowerDNS:

Run the following command to install PowerDNS.
sudo apt-get install pdns-server pdns-backend-mysql
Press ‘Yes’ to configure database for pdns-backend-mysql with dbconfig-common.
sk@server: ~_003
Provide MySQL root user password:
sk@server: ~_004
Then, provide a password for pdns-backend-mysql to register with the database serve.
sk@server: ~_005
Re-enter password:
sk@server: ~_006
PowerDNS has been installed now.

Create PowerDNS Database and User in MySQL

The next step is we should now create the necessary database, user account, tables, and records etc., for the PowerDNS.
Enter to MySQL prompt using command:
sudo mysql -u root -p
Create database, namely ‘powerdns’. You can define your own.
CREATE DATABASE powerdns;
Create database user, namely ‘poweruser’.
GRANT ALL ON powerdns.* TO 'poweruser '@'localhost' IDENTIFIED BY 'ubuntu';
Here,
powerdns – is the database;
poweruser – is the database user,
ubuntu – is the password for the ‘poweruser’ user.
I recommend you to use any strong password to tighten the security.
Enter the following command to update the user settings.
FLUSH PRIVILEGES;
Now, use the powerdns database with command:
USE powerdns;
Create the necessary tables and records.
First, let us create domains table:
CREATE TABLE domains (
id INT auto_increment,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
primary key (id)
);
Create Unique Index for domains table:
CREATE UNIQUE INDEX name_index ON domains(name);
Create records table:
CREATE TABLE records (
id INT auto_increment,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(6) DEFAULT NULL,
content VARCHAR(255) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
primary key(id)
);
Create the following indexes for records table:
CREATE INDEX rec_name_index ON records(name);
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
Create the supermasters table:
CREATE TABLE supermasters (
ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
);
Finally, exit from MySQL prompt using command:
quit;

Configure PowerDNS

Now, we should configure PowerDNS to use MySQL as backend to store Zone files and records.
Remove the existing PowerDNS configuration files.
sudo rm /etc/powerdns/pdns.d/*.*
Then, create file /etc/powerdns/pdns.d/pdns.local.gmysql.conf file;
sudo vi /etc/powerdns/pdns.d/pdns.local.gmysql.conf
Add the following lines. Set the correct database name and database user which we created earlier.
# MySQL Configuration
#
# Launch gmysql backend
launch=gmysql

# gmysql parameters
gmysql-host=localhost
gmysql-dbname=powerdns
gmysql-user=poweruser
gmysql-password=ubuntu
Finally restart powerdns service.
sudo service pdns restart

Test PowerDNS

First, edit /ect/resolv.conf file,
sudo vi /etc/resolv.conf
Set the name server IP address:
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.250
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 192.168.1.250
dns-search home
We completed all installation and configuration parts. Now, we will check whether PowerDNS is really working or not.
First check if PowerDNS is listening:
sudo netstat -tap | grep pdns
Sample output:
tcp        0      0 *:domain                *:*                     LISTEN      1549/pdns_server-in
Now, enter the following command to check PowerDNS is working:
sudo dig @127.0.0.1
Or,
sudo dig @localhost
Sample output:
; <<>> DiG 9.9.5-3-Ubuntu <<>> @127.0.0.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65075
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 2800
;; QUESTION SECTION:
;.                IN    NS

;; Query time: 4 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Mar 30 14:38:58 IST 2015
;; MSG SIZE  rcvd: 29
Or,
sudo dig @192.168.1.250
Where, 192.168.1.250 is my PowerDNS server’s IP address.
Sample output:
; <<>> DiG 9.9.5-3-Ubuntu <<>> @192.168.1.250
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39576
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 2800
;; QUESTION SECTION:
;.                IN    NS

;; Query time: 0 msec
;; SERVER: 192.168.1.250#53(192.168.1.250)
;; WHEN: Mon Mar 30 14:39:49 IST 2015
;; MSG SIZE  rcvd: 29
That’s it. PowerDNS is ready to use. In our upcoming tutorials, let us see how to install and configure PowerDNS web panel called “PowerAdmin”, and how to create zone files and record files.
Cheers!!
==================================================

How To Install PowerDNS On CentOS

In this tutorial, let us see how to install PowerDNS on CentOS 6.5.

Install PowerDNS On CentOS

Scenario:

Operating system: CentOS 6.5 minimal server
IP Address: 192.168.1.150/24
Hostname: server.unixmen.local

Update your system:

First of all, update your system:
Note: The commands in this article is being performed by Root user.
yum update

Setup MySQL:

Install MySQL using command:
yum install mysql-server mysql -y
Start MySQL service and let it to start automatically on every reboot:
service mysqld start
chkconfig mysqld on
Check if MySQL is listening:
netstat -tap | grep mysql
Sample output:
tcp        0      0 *:mysql                     *:*                         LISTEN      1425/mysqld

Set Database Root user password:

By default, Database root password is empty. So, to prevent unauthorized access to your database server, let us set root user password. Enter the following command to setup mysql root user password:
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):     ## Press Enter ## 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]     ## Press Enter ##
New password:                ## Enter new password ##
Re-enter new password:       ## Re-enter new password ##
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]     ## Press Enter ##
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]     ## Press Enter ## 
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]     ## Press Enter ##
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]     ## Press Enter ##
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!
We completed the installation now. Next, we will Install PowerDNS.

Install PowerDNS:

First, install and enable EPEL repository.
rpm -Uvh http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
After installing EPEL repository, run the following command to install PowerDNS.
yum install pdns pdns-backend-mysql bind-utils
After installing PowerDNS, run the following commands to start and enable PowerDNS service to start automatically on every reboot.
service pdns start
chkconfig pdns on
PowerDNS has been installed now.

Create PowerDNS Database and User in MySQL

The next step is we should now create the necessary database, user account, tables, and records etc., for the PowerDNS.
Enter to MySQL prompt using command:
mysql -u root -p
Create database, namely ‘powerdns’. You can define your own.
CREATE DATABASE powerdns;
Create database user, namely ‘poweruser’.
GRANT ALL ON powerdns.* TO 'poweruser '@'localhost' IDENTIFIED BY 'centos';
Here,
powerdns – is the database;
poweruser – is the database user,
centos – is the password for the ‘poweruser’ user.
I recommend you to use any strong password to tighten the security.
Enter the following command to update the user settings.
FLUSH PRIVILEGES;
Now, use the powerdns database with command:
USE powerdns;
Create the necessary tables and records.
First, let us create domains table:
CREATE TABLE domains (
id INT auto_increment,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
primary key (id)
);
Create Unique Index for domains table:
CREATE UNIQUE INDEX name_index ON domains(name);
Create records table:
CREATE TABLE records (
id INT auto_increment,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(6) DEFAULT NULL,
content VARCHAR(255) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
primary key(id)
);
Create the following indexes for records table:
CREATE INDEX rec_name_index ON records(name);
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
Create the supermasters table:
CREATE TABLE supermasters (
ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
);
Finally, exit from MySQL prompt using command:
quit;

Configure PowerDNS

Now, we should configure PowerDNS to use MySQL as backend to store Zone files and records.
Backup the old configuration file.
mv /etc/pdns/pdns.conf /etc/pdns/pdns.conf.bak
Then, create /etc/pdns/pdns.conf file;
vi /etc/pdns/pdns.conf
Add the following lines at the end. Set the correct database name and database user which we created earlier.
# MySQL Configuration
#
# Launch gmysql backend
launch=gmysql

# gmysql parameters
gmysql-host=localhost
gmysql-dbname=powerdns
gmysql-user=poweruser
gmysql-password=centos
Finally, restart powerdns service.
service pdns restart

Test PowerDNS

First, edit your network interface configuration file /etc/sysconfig/network-scripts/ifcfg-eth0,
vi /etc/sysconfig/network-scripts/ifcfg-etho
Set the name server IP address:
DEVICE=eth0
TYPE=Ethernet
UUID=add4274e-d5be-4834-9142-8a85f4444b00
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=08:00:27:DC:33:3F
IPADDR=192.168.1.150
PREFIX=24
GATEWAY=192.168.1.1
DNS1=192.168.1.150

Restart the network service to save the changes.
service network restart
We completed all installation and configuration parts. Now, we will check whether PowerDNS is really working or not.
We must allow the DNS service default port 53 through firewall.
Edit file /etc/sysconfig/iptables,
vi /etc/sysconfig/iptables
Add the following line:
-A INPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT
Save and close the file. Then, restart iptables service.
service iptables restart
Now, enter the following command to check PowerDNS is working:
dig @127.0.0.1
Or,
dig @localhost
Sample output:
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.2 <<>> @localhost
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47553
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;.                IN    NS

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Mar 31 16:08:40 2015
;; MSG SIZE  rcvd: 17
Or,
dig @192.168.1.150
Here 192.168.1.150 is my PowerDNS server’s IP address.
Sample output:
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.2 <<>> @192.168.1.150
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58268
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;.                IN    NS

;; Query time: 0 msec
;; SERVER: 192.168.1.150#53(192.168.1.150)
;; WHEN: Tue Mar 31 16:09:09 2015
;; MSG SIZE  rcvd: 17
That’s it. PowerDNS is ready to use. In our upcoming tutorials, let us see how to install and configure PowerDNS web panel called “PowerAdmin”, and how to create zone files and record files.
Cheers!!

No comments: