HOWTO's

Here you can find some HOWTO's and short tutorials that I've written mostly for myself. If you find some of this information useful and/or have more questions on some of them, drop me a line.

Actualizaciones dinámicas de DNS con BIND9

Hay muchas situaciones donde manejar actualizaciones dinámicas, y en lo posible automáticas, de zonas de DNS es deseable. Por ejemplo en el caso de redes donde hay gran cantidad de estaciones que toman sus direcciones de DHCP o mediante otros mecanismos dinámicos (SLAAC en IPv6 por ejemplo).

dynamic dns update

Configuración del servidor DNS

En el servidor DNS hay que configurar una zona que será la que recibirá las actualizaciones dinámicas. 

Esta zona luego deberá cargarse en BIND de tal manera que acepte actualizaciones dinámicas.

Si bien es posible tener zonas que tengan a la vez entradas estáticas y entradas dinámicas, personalmente no me parece una configuración aconsejable.

En los ejemplos a continuación el nombre de la zona que recibirá las actualizaciones es "intra.labs.lacnic.net"

Creación de la zona "host"

La zona que aloja las actualizaciones dinámicas no tiene ninguna particularidad:

[root@lab etc]# cat db.intra.labs.lacnic.net
$ORIGIN .
$TTL 60 ; 1 minute
intra.labs.lacnic.net   IN SOA  intra.labs.lacnic.net. root.localhost. (
                                4          ; serial
                                604800     ; refresh (1 week)
                                86400      ; retry (1 day)
                                2419200    ; expire (4 weeks)
                                604800     ; minimum (1 week)
                                )
                        NS      mvuy.labs.lacnic.net.
                        A       200.7.84.10
                        TXT     "This zone is meant to be used by dynamically updated hostnames"
                        AAAA    2001:13c7:7001:4000::10
$ORIGIN intra.labs.lacnic.net.
miranda                 A       200.7.85.144
routing-lab-00          A       200.7.85.146
 

Carga de la zona en la configuración de BIND

La zona la cargamos de la siguiente manera:

zone "intra.labs.lacnic.net" {
        type master;
        file "etc/db.intra.labs.lacnic.net";
        allow-update { 200.7.85.0/24; 2001:13c7:7001:5128::/64; };
};
 
En esta configuración la sentencia "allow-update" es la que permite las actualizaciones dinámicas. En este ejemplo estamos controlando el acceso por rangos de IP de origen, es decir en este caso las máquinas que van a poder actualizar el DNS tienen que estar comprendidas en los rangos IP listados.
 
También es posible hacer un control de acceso mas fino usando claves criptográficas.
 

Configuración del cliente

Para que un cliente pueda actualizar el DNS se necesita tener instalada la utilidad "nsupdate". Esta es parte del port "bind-tools" en FreeBSD o de los paquetes "bind-devel" o "bind-tools" en Linux Fedora/Debian/Ubuntu.

La utilidad nsupdate toma un archivo de texto con comandos a pasarle al server. Para actualizar una simple entrada de tipo A lo unico que hace falta es algo asi:

[root@routing-lab-00 ~]# cat nsupdate.d/tmp.update.txt 
server mvuy.labs.lacnic.net
zone intra.labs.lacnic.net
update delete routing-lab-00.intra.labs.lacnic.net
update add routing-lab-00.intra.labs.lacnic.net 60 A 200.7.85.146
show
send
 
Para actualizar el DNS entonces hacemos:
 
# nsupdate ./tmp.update.txt
 

Automatizando el proceso 

Para automatizar el proceso completamente hace falta generar el archivo mencionado en el punto anterior automaticamente con la IP asignada por el servidor de DHCP.

Un ejemplo muy simple de como hacer esto:

1. Crear un script de la forma:

[root@routing-lab-00 ~]# cat nsupdate.d/intra.labs.lacnic.net.txt 
echo server mvuy.labs.lacnic.net
echo zone intra.labs.lacnic.net
echo update delete routing-lab-00.intra.labs.lacnic.net
echo update add routing-lab-00.intra.labs.lacnic.net 60 A $(./get_ip.sh)
echo show
echo send
 
2. Crear un segundo script llamado "get_ip.sh" que imprima la direccion IP en su salida estandard
 
[root@routing-lab-00 ~]# cat get_ip.sh 
#!/bin/sh
IPADDR=`/sbin/ifconfig em0|grep 'inet [0-9]'|tr -s " "|cut -d" " -f2`
echo $IPADDR
 

 

Add "Bazaar Here" Context Menu on Windows XP/2003

I have been using Bazaar as a revision control tool. I have really become used to the ease that not having to create a central repository gives me.

Bazaar for Windows used to include a nifty "Bzr Here" context menu entry which appears to have been deprecated in favor of the nice but alpha-quality Tortoise Bazaar.

Attached below is a registry file to help re-create this context menu entry. Do not blindly double click on it, since you will need to customize your Bazaar installation path as well as the name you wish for the context menu entry. Also, if you make a mistake and need to change values, I'd recommend deleting the newly created keys by hand using regedit.

AttachmentSize
BzrHere.zip349 bytes

CandyPress on Windows Vista (32 bits) and Internet Information Server (IIS) 7

This is a short guide to help those who need to run the CandyPress shopping cart under Windows Vista and Internet Information Server (IIS) 7, including solving the mysterious error -2147467259 (Unspecified Error)

 
Enable Classic ASP on IIS7
Classic ASP is disabled by default in IIS7 (in favor of ASP.NET). To enable Classic ASP you need to go open IIS7's new management interface and go to "Control Panl / Programs and Features / Windows Components / IIS / Classic ASP"
 
Install the Jet Database Engine
Jet's latest version can be downloaded from here (Microsoft). Theoretically, having MS Office installed should suffice but in practice it did not work for me and I had to install this standalone package. Note for 64 bit users: You are out of luck here as Jet won't work under the 64 bit editios of Windows. The recommended upgrade path is to go  to SQL Server Express 2005.
 
Privilege and Security Configuration
  • Enable "Parent Paths" on IIS7 for the CandyPress website we are trying to install. Be careful here and enable it only for the websites you need, since "Parent Paths" is a well-known potential security hole.
  • Grant read/write privileges to all IUSR_something users on the store's MDB (database) file.
  • Do the same for the "C:\Windows\ServiceProfiles\NetworkService\AppData\Local" folder
  • Notes:
    • This last step is what is needed to solve error -2147467259 (Unknown Error). How did I get to this? Using this amazing tool called Process Monitor from SysInternals (now Microsoft). SysInternal's Process Monitor can be downloaded from here (Microsoft).
Test
 
Point your browser to the local URL for the store (http://localhost/cp or similar) and now everything should work.

 

Configurando IPv6 con 6to4 detras de un NAT con IP dinámica

6to4 es uno de los varios mecanismos de transicion de IPv4 a IPv6 que han sido propuestos por el IETF. Es un mecanismo de tunelizacion de IPv6 en un payload IPv4 con la caracteristica adicional de que el extremo remoto del tunel puede congurarse automaticamente ya que usa una direccion well-known como extremo remoto. Es facil de congurar y tiene buena performance. Sin embargo, presenta algunos desafíos a la hora de poderlo utilizar de manera estable detras de un NAT con IP publica variable, como es el caso de la inmensa mayoria de servicios ADSL hogarenos.

En este articulo presento un script que automatiza la conguracion y mantiene operativa la conexion IPv6 utilizando 6to4 utilizando un PC Linux como router IPv6.

Nota: Este trabajo es un work in progress, no puede considerarse completo todavía, aunque el script que se adjunta funciona bien en Ubuntu y Debian.

AttachmentSize
6to4-linux-v1.pdf208.83 KB
6to4-linux-dynip-0.3.tar_.gz143.39 KB

Configuring RNDC for Fine-Grained BIND9 Control

RNDC is an extremely useful utility bundled with BIND that allows controlling the DNS server in a fine-grained way. So instead of reloading the whole server to add a single record, you can issue a "rndc reload myzone.com" command and only that zone will be loaded without restarting the server.

1. Generate a cryptographic key

First we'll generate a crypto key that will be used to access the control channel of BIND:

dnssec-keygen -a HMAC-MD5 -b256 \
    -n HOST rndc

This creates a file named "Krndc.+157+62322" (the numbers will depend on the generated key)

2. Create a configuration file for rndc

This file will not be accesed by BIND, only by rndc. It can be placed anywhere within the system.

---- cut here ----
key "rndckey" {
        algorithm "hmac-md5";
     // this "secret" is the same crypto material found in the
        secret "BxUpUZLIymdkMsfvdrTnudVwefhYEGBbhfRMgAgR81M=";
};

options {
        default-key "rndckey";
        default-server 127.0.0.1;
        default-port 953;
};
---- cut here ----

    •    The name of the key ("rndckey") is arbitrary
    •    Content of the "secret" statement is obtained from private key file generated in step 1.

3. Configure BIND to accept rndc commands

Edit named.conf and include the following statements:

---- cut here ----
# RNDC
key "rndckey" {
        algorithm "hmac-md5";
        secret "BxUpUZLIymdkMsfvdrTnudVwefhYEGBbhfRMgAgR81M=";
};

controls {
        inet 127.0.0.1 allow { 127.0.0.1; } keys { rndckey; };
};
---- cut here ----

4. Restart BIND and test "rndc"

[root@vm3-lab2 var]#  /etc/init.d/bind restart

[root@vm3-lab2 var]# /opt/bind/sbin/rndc -c /path/to/rndc.conf -s localhost status
version: 9.7.2-P3
number of zones: 30
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is ON
recursive clients: 0/0/1000
tcp clients: 0/100
server is up and running
 

Drupal Checklist

This is a short checklist for installing a new Drupal site from scratch:

 

GRUB Recovery Using Fedora 10's LiveCD

If you are like me, chances are that you could not resist the urge to download and install Microsoft's public beta of the upcoming Windows 7 release.

So, I did install it at the expense of having my Fedora 10 GRUB overwritten by Windows 7's installer. Although W7 works fine now, I lost the ability to boot into FC10.

I booted the laptop using my FC 10 LiveCD and tried to do the mount root / chroot / grub-install routine that is described everywhere in the Internet, but I found that the chrooted system has no devices under /dev and this makes grub-install fail.

I went in circles for about half an hour until I came up with a solution: Use mount's "--bind" option to remount the LiveCD's /dev under the chrooted system's /dev.

So the whole procedure goes like this:

And voilá! Happy booting!

 

 

 

Hibernate & Annotations

Hibernate y Annotations

 

La forma tradicional o clásica de usar Hibernate hace que debamos mantener varios archivos XML con diferente información relevante a los objetos que queremos persistir, incluyendo que campos queremos persistir, correspondencia campos <-> tablas e informacion de conexión a la base de datos.

Cada vez que hay un cambio en la aplicación, hay que hacer mantenimiento de:

Esto no solo parece, sino que es, mucho trabajo.

Annotations

Acá entran en juego las Java Annotations. Si agregamos a nuestra aplicacion el paquete Hibernate Annotations tenemos a nuestro alcance una forma mucho mas sencilla de mantener nuestra aplicación.

Las annotations son marcas que compienzan con "@" que se agregan antes de las declaraciones de clases o campos. Con estas annotations podemos marcar que campos son persistentes, que campos son claves primarias y si queremos, como se establece la correspondencia entre tablas y campos.

Annotations es compatible con el paquete javax.persistence y lo bueno de esto es que por ejemplo el Netbeans permite generar clases anotadas directamente desde la estructura de la base de datos.

Compatibilidad

Hibernate Annotations es independiente del IDE que estemos usando (a diferencia de mi método anterior de trabajo que dependía fuertemente del plugin para Eclipse).

Las Annotations en Java están disponibles desde Java 5 en adelante.

IPv6 configuration using 6to4 behind a dynamic IP NAT box

6to4 is one of the many transition mechanisms proposed by the IETF to ease the move towards an IPv6 internet. It is a tunneling protocol which encapsulates IPv6 packets in the payload of an IPv4 packet, with the added feature that the remote endpoint (the 6to4 Relay) of the tunnel configures itself automatically and uses a well-known anycast IPv4 address.

6to4 is easy to setup and gives near-native performance depending on how near you are to a 6to4 relay. However, it presents some challenges when used behind a dynamic IP NAT box, which is the case of the vast majority of home ADSL/Cable broadband services.

In this paper (in Spanish yet only, sorry!) we introduce 6to4 and how to configure it in a Linux box, and we also present a script that configures 6to4 and maintains it working by tracking the IPv4 changes in time. Additionally, using the stateless autoconfiguration daemon radvd it is possible to connect a whole LAN to the IPv6 internet.

Note: This is still a work in progress, the script having being tried only on Ubuntu and Debian.

AttachmentSize
6to4-linux-dynip-0.3.tar_.gz143.39 KB
6to4-linux-v1.pdf208.83 KB

Linux on an IBM x206m with SAS (Serial Attached SCSI) Hard Drives

I had to install Linux (Gentoo) on an IBM x206m server. Remarkable in this box is the use of SATA / SAS (Serial Attached SCSI) hard drives. Only very recent kernels support this kind of storage, and even so they need a firmware blob to be appropiately loaded for the controller to work at all.

Some references can be found on the Internet (although not many). Here is a quick reference of the steps involved to make this box work.

  1. Install Gentoo on an external USB hard drive, or on a temporary IDE drive connected to server.
  1. Compile the kernel, not forgetting to add support for SAS drives in the "aic94xx" module.
  1. Load aic94xx with modprobe and verify that the SAS drives are properly detected.
  2. Proceed with normal Gentoo installation on the USB/IDE drive and later transfer the system to the SAS drives following the "custom stage4" from Gentoo

References:

Mounting "DD" images for forensic purposes

I have created disk images for forensic purposes (artifact analysis and such). The questions is: given a "dd" image created from the whole, raw device, how do I mount individual partitions?

Let's say that the device I want to analyze resides in /dev/sdc, and that I have some large storage mounted under /mnt/largedisk and that I have cread the forensic image using the following command:

# dd if=/dev/sdc of=/mnt/largedisc/mycopy.dd bs=512

When this command ends (it can take up to several hours depending on the size of the disk being imaged), I will have a file that is an exact byte-bye image of the raw device.

In my case, /dev/sdc had two partitions. I was able to mount them using the following command:

# mount -o ro,loop,offset=32256 /mnt/largedisc/mycopy.dd /mnt/dir1

I am using the loop device and the flag "ro" makes sure that the mount will be read-only (a must when doing forensics). The only difficulty here is the number "32256". How did I get it? Simple: use "fdisk" to view the partition layout and use the "start cylinder" value (in my case 63) multiplied by the sector size (usually 512 bytes), and use the result as offset.

How do I use fdisk on a dd image? Simple also:

# sfdisk -l -uS /mnt/largedisc/mycopy.dd

Be careful when copying the large numbers that will result when mounting the rest of the partitions.

ReminderFox 1.9.7 for Thunderbird 3.1 Beta

I´m a frequent user of ReminderFox, a FF/TH extension that, among other things, allows attaching reminders to specific email messages.

Here you can find ReminderFox 1.9.7 modified to install in Lanikai beta1/beta2. The modification was done and tested on a Mac running Snow Leopard, but I guess it should work on other platforms as well.

AttachmentSize
reminderfox-1.9.7-Th31.xpi847.73 KB

Sample Logging Configuration for BIND9

Below you can find a clear configuration snippets to quicklyimplement logging configuration for BIND9. Logging configuration in BIND is, to me, quite obscure and unnecesarily complicated. This sample can be cut & pasted in named.conf (or named.conf.options in Debian / Ubuntu variants). The basis for this configuration was in [http://www.zytrax.com/books/dns/ch7/logging.html]

logging{
  channel simple_log {
    file "/var/log/named/bind.log" versions 3 size 5m;
    severity warning;
    print-time yes;
    print-severity yes;
    print-category yes;
  };
 
  channel queries_log {
    file "/var/log/named/queries.log" versions 3 size 5m;
    severity debug;
    print-time yes;
    print-severity yes;
    print-category yes;
  };
  category default{
    simple_log;
  };
  category queries{
    queries_log;
  };
 
};
 

 

Spanish Dictionary and Dictionary Switcher for Thunderbird 3.1beta1

I user both the Spanish dictionary and the "Dictionary Switcher" extension for Thunderbird. Lately, I have started using Thunderbird 3.1 beta 1 (codename "Lanikai") and these extensions do not work.

I modified the RDF files for both extensions in order to get them installed on Lanikai. I´m attaching the modified XPI files here. Both of them appear to work fine on 3.1b1.

Acknowledgements:

 

AttachmentSize
Diccionario Español Thunderbird 3.1 beta1308.49 KB
Dictionary Switcher for Thunderbird 3.1 beta 13.87 KB