Centos6.5-Win2012R2 – Setup Windows as your Master DNS and Bind as your Slave DNS.

This tutorial show how to setup Windows 2012-R2 as a Master DNS and how to set up Centos 6 as a slave DNS.



The following config files have been used in order to get DNS services up and running in Centos 6.

vi /etc/resolv.conf
search sfentona.lol
vi /etc/sysconfig/network
vi /etc/sysconfig/network-scripts/ifcfg-eth0
vi /etc/named.conf

Under Options you will have to specify the IP address of your Centos DNS server and from which network you will accept queries.

listen-on port 53 {;; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { localhost;; };
//allow-transfer {; };
recursion yes;

Under Zones you will have to create your forward lookup and reverse lookup zones. Between the sections LOGGING and ZONE include the following lines. We are essentially telling to our Centos DNS service that it is of type slave and the IP of the master DNS. We are also telling where the location of the zone files will be located



zone "sfentona.lol" IN {
type slave;
masters {; };
allow-query { any; };
file "slaves/sfentona.lol.zone";


zone "0.0.10.in-addr.arpa" IN {
type slave;
masters {; };
allow-query { any; };
file "slaves/sfentona.lol.rr.zone";





  • On your maind DNS properties settings tree check “Enable Bind Secondaries”
  • You will have enter as Name Server your Linux Server for both your Forward and Reverse Lookup zones.
  • On your DNS Zone (in this case sfentona.lol) under properties settings enable “Zone Transfer”. Specify your slave DNS or you can opt to update all available DNS servers. Make to do this for both your Forward and Reverse lookup zones for your Domain.
Share Button

Python – Centos 6 – PostgresSQL9.4 – Check if PostgresSQL is installed. If not, install it and setup a Database

Script check if postgresql is installed, if it is not it will go ahead and do the appropriate checks to see if the Postgresql YUM RPM packages installed and the proceed to install PostgresSQL. It then does the post configuration steps. It can also create a database with a user assigned to it.

# -*- coding: utf-8 -*-
import psutil
import os
import subprocess
import psycopg2

def install_PostgresSQL():

        if subprocess.call(["rpm", "-q", "pgdg-centos94"]) == 0:

        elif subprocess.call(["rpm", "-q", "pgdg-centos94"]) == 1:
            subprocess.call(["yum", "localinstall", "-y", "http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm"])
            subprocess.call(["yum", "install", "-y", "postgresql94-contrib", "postgresql94-server"])
            print "#################################################################"

    except Exception as e:
        print e
        print "Install failed. Exiting with Error"

def post_install_PostgreSQL():
        path = "/etc/sysconfig/pgsql/"
        fname = 'postgresql-9.4'
        full_path = os.path.join(path, fname)
        file  = open(full_path, "w")
        subprocess.call(["/usr/pgsql-9.4/bin/postgresql94-setup", "initdb"])
        subprocess.call(["systemctl", "enable", "postgresql-9.4"])
        subprocess.call(["systemctl", "start", "postgresql-9.4"])

    except Exception as e:
        print e
        print "Error in Post Install steps"

def create_Database():
        conn = psycopg2.connect("host='' dbname='postgres' user='postgres'")
        cur = conn.cursor() #Create the cursor
        #cur.execute("""SELECT * from servers""")
        conn.autocommit = True
        cur.execute("""CREATE DATABASE test""")
        cur.execute("""CREATE ROLE george WITH PASSWORD 'YourPasswordHere'""")
        cur.execute("""GRANT ALL PRIVILEGES ON DATABASE test to george""")
        #If this is not present the changes will not get commited.
        #for row in cur: #Enable the following two lines to view query results
        #    print rows
    except Exception as e:
        print e

Share Button

Python – Parse URLs from files in directory to check if links are up/down before executing yum on Centos.

This script parses the files in the yum repo directory and checks if all URLS are up before proceeding to execute yum. It creates two lists to do a sanity check. One list stores the number of URLs found and the second list stores the number of links that have been found to be working. If those two numbers do not match the execution of YUM is aborted. Please note, this script will work only with custom made yum repos.

import os
import subprocess
import re
import urllib2
import os.path

def check_Software():
    path = '/usr/bin/gcc'
    if os.path.isfile(path):
            subprocess.call(["yum", "install", "-y", "gcc"])
            if not os.patch.isfile(path):
                print "Sending email"

        except OSError as er:
            print er

def yum_link_Search():
    #These two lists are being used as control. The status list is used to append succesful HTTP connections
    #for each of the URLs captured from the files in the YUM directory. The latter is stored in the files_list list.
    #The number (amount of elements) is being compared. A success condition is when each site returns an alive code of
    #200. This tells us that all sites are up and running. View lines between 52 and 60
    status_list = []
    files_list = []
    src_dict = ("/etc/yum.repos.d/") #Specify base directory
    pattern = re.compile ('http\S+') #CPatter to search for

    for yum_files in os.listdir(src_dict): # obtain list of files in directory
        files = os.path.join(src_dict, yum_files) #join the full path with the names of the files.
        strng = open(files) #We need to open the files
        for lines in strng.readlines(): #We then need to read the files
            if re.search(pattern, lines): #If we find the pattern we are looking for
                print re.split(r'=', lines)[1] #We split using as a delimeter the = sign.

                    status_link = urllib2.urlopen(re.split(r'=', lines)[1]).getcode()
                    #if  status_link == 200: #Check if the site is up
                    status_list.append(status_link)#View notes starting on line 29 for these conditionals
                    print status_list
                    print files
                    if len(files_list) > len(status_list): #View notes starting on line 29 for these conditionals
                        print "Not all Links are up - ABORTING"
                    if len(files_list) < len(status_list):
                        print "Not all Links are up - ABORTING"
                    elif len(files_list) == len(status_list):
                        print "Will run yum installer" #here we can call other functions since everything seems to be working fine.
                        #call the yum function here
                except StandardError as er:#Here we are capturing errors of other codes.
                    print "Site down"
                    print status_link

Share Button

Centos 6.5 – Create a YUM repository for your private network.

This tutorial shows how to create a YUM repository which you can use on your own private network. You may want this if you do not want your production servers to reach on the Internet thus keeping them protected. These servers will get their RPM packages by a server that holds the always up to date RPM packages. This is called the repository server and it will need access to the Internet in order to get the latest RPM packages.



1) Find an official CentOS site that supports RSYNC. List of Links here.

2) Have a spare server to use as your Repo server. This server will need to have Apache installed.

3) Enter an DNS entry for the local web site you will create that will host the RPM packages.

4) Setup yum on your servers to get the new packages from your Repo Server.

Continue reading

Share Button

Centos 6.5 – Add a local repo in 5 small steps

You can set yum to draw RPM packages for install directly from your DVD drive by executing the following steps.

  • 1) Enable yum to read from your local DVD.

                              vi /etc/yum.repos.d/CentOS-Media.repo

  • 2) Set the parameter enabled to 1
  • 3) Create a directory to use as a mount point for your DVD.

                             mkdir /media/cdrom

  • 4) Mount your DVD drive.

                             mount -t iso9660 /dev/cdrom /media/cdrom

  • 5) Install software

                            yum –enablerepo=c6-media install httpd



Share Button

CentOS 6 – Setup a Transparent Squid proxy Server

“In computer networks, a proxy server is a server that acts as an intermediary for requests from clients seeking resources from other servers”  Wikipedia link.  In other words machine XYZ that is located within your network, instead of connecting directly to the internet to request a web page   it will go through the proxy server. With a more advanced setup you can control access to  SSH , FTP and so on.  This adds a layer of security because you can control what type of requests your users are allowed to use and you can also impose rules as to what your users can do with already allowed requests.  In addition you can create a cache of web pages that will reside in your proxy server. This reduces the overhead on the network because the contents of web pages do not have to fetched from the Internet each time your users request it.

Continue reading

Share Button

How to upgrade Postgresql from 8x to 9.2.6 – Centos 5.9 and Centos 6.4

These upgrades retain the old database engine while installing the new version as well. However, in order to have both engines running you will need to change the port on which each engine is listening to. Remember, two applications cannot use the same port over the network for incoming connections.  The directory structure of the Postgresql 8x is

  • /var/lib/pgsql/data

Once you upgrade to version 9.2.6 the directory structure for your new engine will be

  • /var/lib/pgsql/9.2
Share Button