DataMapper out of range value for column ‘id’

If you are reading this, you are (probably) using DataMapper and are having problems like this:

Exception `DataObjects::DataError' at dm-do-adapter/adapter.rb:279
Out of range value for column 'id' at row 1 (code: 1264, sql state: 22003, 
query: INSERT INTO `workspaces` (`id`, `name`) VALUES (2348944937325, 'Stardata S.r.l.')
[...]

The problem is that the default field created by DataMapper for an Integer property is a 32bit INT (at least on MySQL 5.5). If you want to store bigger integers you should use the :min and :max parameters, for example:

class Workspace
  include DataMapper::Resource

  property :id, Integer, :key => true, :min => 0, :max => 281474976710656
  property :name, String

end

Then DataMapper will use a BIGINT for the field.

Dynamic DNS updates for DHCP on Ubuntu 12.04

Configuring your nameserver for dynamic updates for DHCP hosts is a common task, but the online documentation is a bit outdated and incorrect in many ways. Let’s fix it.

A basic DNS configuration will look like this:

/etc/bind/named.conf

include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.dhcpupdate";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

We added the include named.conf.dhcpupdate to the default file. Let’s see the rest.

/etc/bind/named.conf.options

options {
        directory "/var/cache/bind";

        forwarders {
                8.8.8.8;
                8.8.6.6;
        };

        auth-nxdomain no;    # conform to RFC1035
        listen-on-v6 { any; };
};

We used Google DNS servers as forwarders (it’s a good default).

/etc/bind/named.conf.dhcpupdate

key dhcpupdate {
  algorithm hmac-md5;
  secret "waZulpdc0rzMahbulbd34C==";
};

We created the key using:

$ su -
passwd:
# cd /etc/bind/
# dnssec-keygen -a hmac-md5 -b 128 -n USER dhcpupdate
[...]
# cat Kdhcpupdate.+157+31337.key
dhcpupdate. IN KEY 0 3 157 waZulpdc0rzMahbulbd34C==

You should create your own key, otherwise everyone reading this post will be able to tamper with your DNS :)

/etc/bind/named.conf.local

zone "stardata.lan" {
        type master;
        file "/var/cache/bind/db.stardata.lan";
        allow-update { key dhcpupdate; };
};

zone "0.168.192.in-addr.arpa" {
        type master;
        notify no;
        file "/var/cache/bind/db.192";
        allow-update { key dhcpupdate; };
};

It’s very important that your zone files are in /var/cache/bind/, otherwise AppArmor will deny the write permissions to named and the daemon will not update the zones.

/etc/bind/named.conf.default-zones

We kept the default for this file and related files (db.root, db.local, db.127, db.0, db.255)

/var/cache/bind/db.stardata.lan

$ORIGIN .
$TTL 7200 ; 2 hours
stardata.lan            IN SOA  gw.stardata.lan. hostmaster.stardata.lan. (
                                2012070901 ; serial
                                3600       ; refresh (1 hour)
                                1800       ; retry (30 minutes)
                                604800     ; expire (1 week)
                                7200       ; minimum (2 hours)
                                )
                        NS      gw.stardata.lan.
$ORIGIN stardata.lan.
$TTL 3600 ; 1 hour
dns                     A       192.168.0.2
gateway                 A       192.168.0.2
gw                      A       192.168.0.2
ns                      A       192.168.0.2

This is a very simple and basic configuration, covering only our DNS server (192.168.0.2).

/var/cache/bind/db.192

$ORIGIN .
$TTL 604800     ; 1 week
168.192.in-addr.arpa    IN SOA  gw.stardata.lan. hostmaster.gw.stardata.lan. (
                                2012050804 ; serial
                                604800     ; refresh (1 week)
                                86400      ; retry (1 day)
                                2419200    ; expire (4 weeks)
                                604800     ; minimum (1 week)
                                )
                        NS      gw.
$ORIGIN 0.168.192.in-addr.arpa.
2                       PTR     gw.stardata.lan.

And this is the reverse zone.

Now, you’ll want to test this configuration. Restart bind (service bind9 restart), then create a PTR and an A record:

$ nsupdate
> server localhost
> key dhcpupdate waZulpdc0rzMahbulbd34C==
> zone 0.168.192.in-addr.arpa
> update add 50.0.168.192.in-addr.arpa 600 IN PTR provaprova.stardata.lan.
> send
> server localhost
> key dhcpupdate waZulpdc0rzMahbulbd34C==
> zone stardata.lan
> update add provaprova.stardata.lan. 600 IN A 192.168.0.50
send

If you don’t have any errors, then you can delete the temp record:

$ nsupdate
> server localhost
> key dhcpupdate waZulpdc0rzMahbulbd34C==
> zone stardata.lan
> update delete provaprova.stardata.lan
> send

If you have any errors, check /var/log/syslog for error messages. I had a NOTZONE error first, because I was using stardata.lan instead of 0.168.192.in-addr.arpa as the zone for the PTR record. I had a SERVFAIL error due to AppArmor denying write permissions on zone files (you should not see this).

Back to DHCP configuration:

/etc/dhcp/dhcpd.conf

ddns-updates on;
ddns-domainname "stardata.lan";
ddns-update-style interim;

key dhcpupdate {
  algorithm hmac-md5;
  secret waZulpdc0rzMahbulbd34C==;
}

option domain-name "stardata.lan";
option domain-name-servers 192.168.0.2;
default-lease-time 7200;
max-lease-time 86400;
authoritative;
log-facility local7;

subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.130 192.168.0.149;
  option routers 192.168.0.2;
  option domain-name-servers 192.168.0.2;
}

zone 168.192.in-addr.arpa {
  primary ns.stardata.lan;
  key dhcpupdate;
}

zone stardata.lan {
  primary ns.stardata.lan;
  key dhcpupdate;
}

The ddns-* and the zone directives enable the DNS updating.

Sources: BIND 9 Server Howto, Dynamic DNS and DHCP – Easy tutorial.