diff --git a/contrib/bin/fusiondirectory-setup b/contrib/bin/fusiondirectory-setup
index 22a515a1dce38ccbe13277c059cbd74a1623a833..2566369902585c75329b4d43ac89923820d2a8c2 100644
--- a/contrib/bin/fusiondirectory-setup
+++ b/contrib/bin/fusiondirectory-setup
@@ -1454,16 +1454,17 @@ sub migrate_dhcp {
   } else {
     if (ask_yn_question("Move these entries to the DHCP branch ($dhcprdn)?")) {
       foreach my $entrydn (@baddns) {
-        $entrydn =~ m/^([^,]+),(.+$systemrdn,(.+))$/ or die "Could not parse dn ".$entrydn."\n";
+        $entrydn =~ m/^([^,]+),(cn=(.+),$systemrdn,(.+))$/ or die "Could not parse dn ".$entrydn."\n";
         my $rdn = $1;
         my $systemdn = $2;
-        my $entrybase = $3;
+        my $systemcn = $3;
+        my $entrybase = $4;
         if (!branch_exists($ldap, "$dhcprdn,$entrybase")) {
           create_branch($ldap, $entrybase, $dhcprdn);
         }
         my $result = $ldap->moddn (
           $entrydn,
-          newrdn        => $rdn,
+          newrdn        => "$rdn-$systemcn",
           deleteoldrdn  => '1',
           newsuperior   => "$dhcprdn,$entrybase"
         );