gethostbyname() vs getaddrinfo()

In IPv4 environment(usually) we used to call function gethostbyname() to do DNS lookups.then the information is load into a struct hostent.

#include <netdb.h>
struct hostent *gethostbyname(const char *name);

struct  hostent {
        char    *h_name;        /* official name of host */
        char    **h_aliases;    /* alias list */
        int     h_addrtype;     /* host address type */
        int     h_length;       /* length of address */
        char    **h_addr_list;  /* list of addresses from name server */
};
#define h_addr  h_addr_list[0]  /* address, for backward compatibility */

So, the easiest way to get information from gethostbyname() call is by extracting hostent structure.

Using VIM as stream editor

Every person associated with the unix / linux would be familiar with the text editor called vi / vim. but not many people know that vi / vim can be used as a stream editor. This is one example of how to use vi / vim as a text editor.…

vmware ESXi 4 + centos 5.3 guest OS + zimbra

I’ve been playing around with Zimbra opensource edition on my development server. Zimbra is a full-featured, open source collaboration suite for  email, group calendaring, contacts, and web document management and authoring. web interface is equipped with AJAX and it is compatible with clients such as Outlook, Apple Mail, and Novell Evolution so that mail, contacts, and calendar items can be synchronised from these to the ZCS server. It also can be synchronized to many mobile devices. ZCS makes use of many existing open source projects such as Postfix, MySQL, and OpenLDAP.

In this experiment i was using Zimbra 64bit_x86 opensource edition

DNs setting

mail.domain.tld.        A    192.168.1.2
domain.tld.             MX   10    mail.domain.tld.

Download the installer

# wget http://h.yimg.com/lo/downloads/6.0.1_GA/zcs-6.0.1_GA_1816.RHEL5_64.20090911174852.tgz

Extract the installer tarball, make sure we have enough space.

# tar xvzf  6.0.1_GA/zcs-6.0.1_GA_1816.RHEL5_64.20090911174852.tgz
# cd zcs-6.0.1_GA_1816.RHEL5_64.20090911174852

Querying Visitor IP address

There are many ways, scripting/language to obtain remote IP address of the user who is browsing our website.

PERL

#!/usr/bin/perl
use CGI;
print "Content-type: text/plain; charset=iso-8859-1\n\n";
my $q = new CGI;
print "<b>Your Remote IP Address :" . $q->remote_host() . "</b>";

PHP

<?php
echo "<b>Your Remote IP Address :" . $_SERVER['REMOTE_ADDR'] . "</b>";
?>

Setup Google Apps For your Personal eMail

I was realy surprised on how easy it was to set up hosting using google apps. Fisrt of all, all we need is just go here and fill out the application.

if you’re using it for family, private user or non-profit organisation google apps is freely to use. Of course we can Upgrade to Google Apps Premier Edition for bigger storage at 25 GB per user.

The first step of the application is to enter your domain name, if you already have one. Or you can buy a new domain name through Google which automatically sets everything up for you.

 

Securing MySQL traffic with stunnel

To encrypt a connection between a mysql client and a mysql server, run two instances of stunnel, one on client site and other on MySQL remote site

Here’s steps how to do it

# wget http://www.stunnel.org/download/stunnel/src/stunnel-4.27.tar.gz
# rpmbuild -ta stunnel-4.27.tar.gz
# rpm -ivh /usr/src/redhat/RPMS/stunnel-4.27-1.i386.rpm

Create stunnel.pem cert on server site

# openssl genrsa -out privkey.pem 2048
# openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
# cat privkey.pem cacert.pem >> /etc/stunnel/stunnel.pem

Set the proper permissions on the resulting private key:

# chmod 0400 /etc/stunnel/stunnel.pem

Set the proper ownership of the stunnel chroot dir

# chown nobody:nobody /var/run/stunnel

Defining delegated route /48 from Hurricane Electric in Appropriate way.

I’ve been thinking on how to create reverse zone for /64 subnet from delegated routed /48 from Hurricane Electric. First when i was first time request delegation for routed /48 i’ve defined this configuration on my nameservers

In named.conf

zone "7.e.8.f.0.7.4.0.1.0.0.2.ip6.arpa" {
type master;
file "reverse-2001-470-f8e7_48.IP6.ARPA";
};

Sending HTML mail via sendmail cli

Here’s how to do it

# ( cat <<HEADERS; cat /root/file.html) | sendmail -oi -t
From: sender@domain.tld
To: recipients@domain.tld
Subject: we send HTML instead of plain text
Mime-Version: 1.0
Content-type: text/html
Content-transfer-encoding: 8bit

HEADERS <- type CTRL+D then press ENTER

We should set Mime-Version , Content-Transfer-Encoding and Content-Type headers properly. The issue of correct MIME transfer encoding is one of the many possible complexities which is simply ignored here.

Upgrading Bind9 on centos 4.7

I’ve just upgrading one of my dns server recently. Orginaly centos 4.7 using bind-9.2.4-30.el4_7.2. Although this version not affected by cache poisoning vulnerability. as Dan Kaminsky  announced a massive, multi-vendor issue with DNS that could allow attackers to compromise any name server. Here’s how to upgrade bind-9.2.4 to bind-9.5.0.

Download the SOURCE rpms

# wget http://patrick.vande-walle.eu/upload/bind-9.5.0-33.P1.src.rpm

Compile/Build source RPM

# rpm -Ivh bind-9.5.0-33.P1.src.rpm
# cd /usr/src/redhat/SPECS/
# vi bind.spec

find this lines

# configuration files:
tar -C ${RPM_BUILD_ROOT} -xf %{SOURCE28}

change it to

tar -C ${RPM_BUILD_ROOT} -xjf %{SOURCE28}

Source28 is tar.bz2 file so we need tar -xjf options