change ipv4 address

i'm using nixops with virtualbox and using virtualbox'es dhcp server used to ignore reassigning same IPs to same MAC addresses i replaced it by isc-dhcpd with this setup:

  services.dhcpd = {
    enable = true;
    interfaces = "vboxnet0";
    extraConfig = ''
      # https://en.wikipedia.org/wiki/Reserved_IP_addresses
      subnet 198.18.0.0 netmask 255.254.0.0
      {
        range 198.18.0.10 198.19.255.254;
        default-lease-time 3600;
        max-lease-time 3600;
 
        #host foo
        #   {
        #     hardware ethernet 00:30:6f:88:23:1b;
        #     fixed-address 10.0.0.10;
        #   }
      }
  '';
  };

next thing i needed to do was to update the ipv4 addresses in the VMs, which goes like this:

1. reboot the virtualbox VM and see which ipv4 address is assigned:

    root@lenovo-t530 /home/joachim/.nixops # journalctl -u dhcpd -f
    -- Logs begin at Fr 2014-09-19 11:04:40 CEST. --
    Jun 30 15:43:54 lenovo-t530 dhcpd[17775]: DHCPNAK on 10.0.2.15 to 08:00:27:ac:fd:91 via vboxnet0
    Jun 30 15:43:54 lenovo-t530 dhcpd[17775]: DHCPDISCOVER from 08:00:27:ac:fd:91 via vboxnet0
    Jun 30 15:43:55 lenovo-t530 dhcpd[17775]: DHCPOFFER on 198.18.122.48 to 08:00:27:ac:fd:91 (webserver) via vboxnet0
    Jun 30 15:43:55 lenovo-t530 dhcpd[17775]: DHCPREQUEST for 198.18.122.48 (198.18.0.1) from 08:00:27:ac:fd:91 (webserver) via vboxnet0
    Jun 30 15:43:55 lenovo-t530 dhcpd[17775]: DHCPACK on 198.18.122.48 to 08:00:27:ac:fd:91 via vboxnet0
    Jun 30 15:43:55 lenovo-t530 dhcpd[17775]: DHCPREQUEST for 198.18.122.48 (198.18.0.1) from 08:00:27:ac:fd:91 via vboxnet0
    Jun 30 15:43:55 lenovo-t530 dhcpd[17775]: DHCPACK on 198.18.122.48 to 08:00:27:ac:fd:91 via vboxnet0
    Jun 30 16:09:17 lenovo-t530 dhcpd[17775]: Can't create new lease file: Permission denied
    Jun 30 16:09:17 lenovo-t530 dhcpd[17775]: DHCPREQUEST for 198.18.122.48 from 08:00:27:ac:fd:91 via vboxnet0
    Jun 30 16:09:17 lenovo-t530 dhcpd[17775]: DHCPACK on 198.18.122.48 to 08:00:27:ac:fd:91 (webserver) via vboxnet0
    

2. now change the sqlite databse:

   cd ~/.nixops/
   sqlite3 deployments.nixops
   sqlite> .tables
   DeploymentAttrs  ResourceAttrs    SchemaVersion  
   Deployments      Resources   

query the address:

   sqlite> select value from ResourceAttrs where machine=10 and name="privateIpv4";
   10.0.2.15

override the address:

   sqlite> update ResourceAttrs set value="198.18.122.48"  where machine=10 and name="privateIpv4";

check

   sqlite> select value from ResourceAttrs where machine=10 and name="privateIpv4";
   198.18.122.48

finally save:

   .save deployments.nixops

3. finally boot the VM

Powered by MediaWiki