Monday 6 August 2012

Install PowerDNS with mySQL backend

Installing PowerDNS (With MySQL Backend) And Poweradmin On Ubuntu 10.04 LTS

1. Installing MySQL
In order to install MySQL, we run

aptitude install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user - this password is valid for the user root@localhost as well as root@server1.example.com, so we don't have to specify a MySQL root password manually later on (as was the case with previous Ubuntu versions):
New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
We want MySQL to listen on all interfaces (this is important for MySQL replication!), not just localhost, therefore we edit /etc/mysql/my.cnf and comment out the line bind-address = 127.0.0.1:

vi /etc/mysql/my.cnf

[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address
[...]

Then we restart MySQL:

/etc/init.d/mysql restart

Now check that networking is enabled. Run

netstat -tap | grep mysql

The output should look like this:

root@server:~# netstat -tap | grep mysql
tcp        0      0 *:mysql                 *:*                     LISTEN      1027/mysqld
root@server:~#

2. Installing PowerDNS

To install PowerDNS, we run
aptitude install pdns-server pdns-backend-mysql
The PowerDNS configuration is located in the /etc/powerdns directory - I'll come to that in a moment.
Now we connect to MySQL:

mysql -u root -p

Type in your MySQL root password, and you should be on the MySQL shell. On the MySQL shell, we
create a database for PowerDNS:

CREATE DATABASE powerdns;

Next we create a database user (powerdns) for PowerDNS:

GRANT ALL ON powerdns.* TO 'power_admin'@'localhost' IDENTIFIED BY  'power_admin_password';
GRANT ALL ON powerdns.* TO 'power_admin'@'localhost.localdomain' IDENTIFIED BY 'power_admin_password';
FLUSH PRIVILEGES;
(Replace power_admin_password with a password of your choice.)

Now we create the tables needed by PowerDNS...

USE powerdns;
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 name_index ON domains(name);
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 INDEX rec_name_index ON records(name);
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE TABLE supermasters ( ip VARCHAR(25) NOT NULL, nameserver VARCHAR(255) NOT  NULL, account VARCHAR(40) DEFAULT NULL );

... and finally leave the MySQL shell:

quit;

Now we must configure PowerDNS so that it uses the MySQL backend:

vi /etc/powerdns/pdns.conf
Add the line launch=gmysql to pdns.conf:

[...]
#################################
# launch        Which backends to launch and order to query them in
#
# launch=
launch=gmysql
[...]

Then open /etc/powerdns/pdns.d/pdns.local and make it look as follows:

vi /etc/powerdns/pdns.d/pdns.local

# Here comes the local changes the user made, like configuration of
# the several backends that exists.

gmysql-host=127.0.0.1
gmysql-user=power_admin
gmysql-password=power_admin_password
gmysql-dbname=powerdns

Then restart pdns:

/etc/init.d/pdns restart

That's it, PowerDNS is now ready to be used. To learn more about it, please refer to its documentation: http://downloads.powerdns.com/documentation/html/index.html

3. Installing Poweradmin

Now let's install Poweradmin, a web-based control panel for PowerDNS. Poweradmin is written in PHP, so we must install a web server (I'm using Apache2 in this example) and PHP:

aptitude install apache2 libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php-pear php5-imap php5-mcrypt php5-mhash php5-ming php5-mysql php5-xmlrpc gettext

Poweradmin also requires the following two PEAR packages:


pear install DB
pear install pear/MDB2#mysql

Restart Apache:

/etc/init.d/apache2 restart

Now all prerequisites for Poweradmin are installed, and we can begin with the Poweradmin installation (I will install it in a subdirectory of /var/www - /var/www is the document root of Apache's default web site on Ubuntu; if you've created a vhost with a different document root, please adjust the paths).
Go to https://www.poweradmin.org/trac/wiki/GettingPoweradmin and download the latest Poweradmin package, e.g. as follows:

cd /tmp
wget https://www.poweradmin.org/download/poweradmin-2.1.4.tgz
Then install it to the /var/www/poweradmin directory as follows:
tar xvfz poweradmin-2.1.4.tgz
mv poweradmin-2.1.4 /var/www/poweradmin
touch /var/www/poweradmin/inc/config.inc.php
chown -R www-data:www-data /var/www/poweradmin/






Thursday 8 March 2012

How to assign static IP - Ubuntu


It is not intuitively obvious how to assign Ubuntu 10.04 Lucid Lynx a static IP address from the command line. However, much of Linux administration involves the editing of text files, and assigning a static IP address is no different. You’ll need to edit the following file:

/etc/network/interfaces

Initially, the file only contains information about your local loopback address:

auto lo
iface lo inet loopback

To assign a static IP address, you’ll need to make some changes to this file.
Let’s say you want to assign a static IP of 192.168.1.2 to your eth0 network connection (the first Ethernet adapter on your system; if you only have one, it will be eth0), with a subnet mask of 255.255.255.0 and a local gateway of 192.168.1.1. First, make a backup copy of the interfaces file:
sudo cp /etc/network/interfaces ~
This will make a backup copy in your home directory in case something goes amiss during the editing process. Next, fire up a text editor:

sudo vi /etc/network/interfaces

(Obviously you can substitue emacs or your editor of choice.)
Once the file is open, add the following lines:
iface eth0 inet static
address 192.168.1.2
netmask 255.255.252.0
gateway 192.168.1.1

Once you’ve added these lines, save the interfaces file to disk, and exit your text editor. If you want to add a static DNS server, you’ll need to edit the /etc/resolv.conf file with this command:
sudo vi /etc/resolv.conf
To set a static DNS server with the address of 192.168.1.10, add this line to the file:
nameserver 192.168.1.10
Save the file, and exit your text editor.
You’ll then to need have your system load the new IP configuration. You can do that by rebooting, but if that takes too long, you can use this command to force Ubuntu to re-read the configuration files:
sudo ifup eth0
Your system will then have a static IP address.

Monday 5 March 2012

how to Tar and Untar in Unix CLI

Tar file can come compressed or uncompressed. Generally that are compressed using gzip or bzip2. The program, tar, will uncompressed both types and extract the files from archive in Ubuntu.

Step 1:
Install tar using "apt-get install tar"

Step 2:
 Type at the command prompt
tar xvzf file-1.0.tar.gz - for uncompress a gzip tar file (.tgz or .tar.gz)
tar xvjf file-1.0.tar.bz2 - for uncompress a bzip2 tar file (.tbz or .tar.bz2)
tar xvf file-1.0.tar - for uncompressed tar file (.tar)
  • x = eXtract, this indicated an extraction ( c = create to create )
  • v = verbose (optional) the files with relative locations will be displayed.
  • z = gzip-ped; j = bzip2-zipped
  • f = from/to file ... (what is next after the f is the archive file)

Install PowerDNS with mySQL backend

Installing PowerDNS (With MySQL Backend) And Poweradmin On Ubuntu 10.04 LTS 1. Installing MySQL In order to install MySQL, we run apt...