Changing computer name on DNS SAMBA4 AD Server

I have attempted to join a windows computer to the domain I have created on a raspberry pi using SAMBA4.

When joining I get the following error:

The following domain controllers were identified by the query: raspberrypi.mydomain.local However no domain controllers could be contacted.

The reason for this is because the machine name is NOT raspberrypi but something else (AD01)

doing a check of the DNS returns the following

samba-tool dns query localhost mydomain.local @ ALL -U administrator
Global parameter tls enabled found in service section!
Global parameter tls keyfile found in service section!
Global parameter tls certfile found in service section!
Cannot do GSSAPI to an IP address
Password for []:
Name=, Records=3, Children=0
SOA: serial=1, refresh=900, retry=600, expire=86400, minttl=3600, ns=raspberrypi.mydomain.local., email=hostmaster.mydomain.local. (flags=600000f0, serial=1, ttl=3600)
NS: raspberrypi.mydomain.local. (flags=600000f0, serial=1, ttl=900)
A: 192.168.31.10 (flags=600000f0, serial=1, ttl=900)
Name=_msdcs, Records=0, Children=0
Name=_sites, Records=0, Children=1
Name=_tcp, Records=0, Children=4
Name=_udp, Records=0, Children=2
Name=DomainDnsZones, Records=0, Children=2
Name=ForestDnsZones, Records=0, Children=2
Name=raspberrypi, Records=1, Children=0
A: 192.168.31.10 (flags=f0, serial=1, ttl=900)

How do I change the above DNS to point to the correct computer name?

I have managed to change the nameserver entry with the following command,

samba-tool dns update localhost mydomain.local @ NS raspberrypi.mydomain.local AD01.mydomain.local -U Administrator

however the SOA entry refuses to change showing the error "Error: Record does not exist" This is the command I am executing:

samba-tool dns update localhost mydomain.local @ SOA "raspberrypi.mydomain.local hostmaster.mydomain.local 1 900 600 86400 3600" "AD01.mydomain.local hostmaster.mydomain.local 1 900 600"

Solution 1:

After much trial and error I finally figured out the commands.

I have posted this as an answer to help anyone else in the future

First add A records for the new name (in my case I am changing raspberrypi to AD01)

Add the new computer name into DNS

samba-tool dns add localhost mydomain.local AD01 A 192.168.31.10 -U Administrator

Update the NameServer entry

samba-tool dns update localhost mydomain.local @ NS raspberrypi.mydomain.local AD01.mydomain.local -U Administrator

Now update the SOA record, first query the DNS to get the serial

samba-tool dns query localhost mydomain.local @ ALL -U Administrator

this will return the current SOA entry, the important parts are in bold:

SOA: serial=4, refresh=900, retry=600, expire=86400, minttl=3600, ns=raspberrypi.mydomain.local., email=hostmaster.mydomain.local. (flags=600000f0, serial=4, ttl=3600)

Then use that information to update the entry (format is ns email serial refresh retry expire minttl) from the above output and don't forget the trailing . on the entries!!!

samba-tool dns update localhost mydomain.local @ SOA 'raspberrypi.mydomain.local hostmaster.mydomain.local 4 900 600 86400 3600' 'AD01.mydomain.local hostmaster.mydomain.local 4 900 600 86400 3600' -U Administrator