Wednesday, 9 December 2015

Linux: Search files and replace x with y

This command will check all files and folders within the current directory and replace x with y

sudo find ./ -type f -exec sed -i -e 's/x/y/g' {} \;

Monday, 9 November 2015

PHP: User login, resticted pages, redirects, bootstrap with MySQL using sessions

PHP: User login, resticted pages, redirects, bootstrap with MySQL using cookies

Login.php/login_page.inc.php - Main login page
CRMmain.php - Redirects here after successfuly login - Redirect to login.php if no cookies
mysqliadl.php - Database connection
login_functions.inc.php - Checks user/pass with database
logout.php - Destroys cookies and redirects to login.php


Thursday, 29 October 2015

Wednesday, 11 February 2015

BIND9: Setup and configuration

Install the following;

  • sudo apt-get install bind9 dnsutils bind9-doc
 

Caching Server configuration


If you want to configure DNS forwarders, you can do this in;

  •  sudo nano /etc/bind/named.conf.options

For example;

forwarders {
8.8.8.8;
8.8.4.4;
};


Zone File


To create zones edit the following file;

  •  sudo nano /etc/bind/named.conf.local 
Here is an example of my zones which includes our local Active Directory Domain Controller, PBX, and a zone for the internal network.


For easier management I created a zone directory;

  • sudo mkdir /etc/bind/zones

Create a zone file that is referenced in named.conf.local;

  • sudo cp /etc/bind/db.local /etc/bind/zones/db.bluetelecoms.com


Replace XXX with correct details.

Reverse Zone File


Now create the reverse zone file, copy an existing template to start from;

  • sudo cp /etc/bind/db.local /etc/bind/zones/db.bluetelecoms37

Where XXX is the last octet of the ip address (the rest was defined in named.conf.local file zone "90.187.37.in-addr.arpa"....).

Testing


Use ping, dig, host, and named-checkzone to test your configuration;
 


Plain Example


If you are having issues, I used the following example from tecmintlocal (see link at bottom) to start off from with some minor changes;

sudo nano /etc/bind/named.conf.options

forwarders {
        192.168.1.249;
        };

sudo /etc/init.d/bind9 restart

dig @127.0.0.1 ubuntu.com

sudo nano /etc/bind/named.conf.local

zone "tecmintlocal.com" {
        type master;
        file "/etc/bind/zones/db.tecmintlocal.com";
        };

sudo cp /etc/bind/db.local db.tecmintlocal.com
sudo nano db.tecmintlocal.com

;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     tecmintlocal.com. root.tecmintlocal.com. (
                     2014082801         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.tecmintlocal.com.
ns      IN      A       192.168.1.241

clt1    IN      A       192.168.1.111
ldap    IN      A       192.168.1.200
ldapc   IN      A       192.168.1.211
mail    IN      CNAME   clt1.tecmintlocal.com.

sudo service bind9 restart
dig @127.0.0.1 mail.tecmintlocal.com

sudo nano /etc/network/interfaces

auto eth0
iface eth0 inet static
        address 192.168.1.214
        netmask 255.255.255.0
        gateway 192.168.1.254
        network 192.168.1.0
        broadcast 192.168.1.255
        dns-nameservers 127.0.0.1
        dns-search tecmintlocal.com

sudo reboot now
ping clt1.tecmintlocal.com -c 3
sudo nano /etc/bind/named.conf.local

zone "1.168.192.in-addr.arpa" {
        type master;
        notify no;
        file "/etc/bind/db.tecmintlocal192";
        };

sudo cp db.127 db.tecmintlocal192
sudo nano db.tecmintlocal192

;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA     ns.tecmintlocal.com. root.tecmintlocal.com. (
                        2014082802      ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.
241     IN      PTR     ns.tecmintlocal.com.

111     IN      PTR     ctl1.tecmintlocal.com.
200     IN      PTR     ldap.tecmintlocal.com.
211     IN      PTR     ldapc.tecmintlocal.com.

sudo service bind9 restart
host 192.168.1.111
dig clt1.tecmintlocal.com

Sources;
https://help.ubuntu.com/community/BIND9ServerHowto
http://www.tecmint.com/install-dns-server-in-ubuntu-14-04/