-
-
Save mbrownnycnyc/5644413 to your computer and use it in GitHub Desktop.
| #!/bin/sh | |
| #original from http://community.spiceworks.com/topic/262635-linux-does-not-register-on-the-windows-ad-dns | |
| # reply of Phil6196 Oct 1, 2012 at 12:41 AM (EDT) | |
| ADDR=`/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e s/.*://` | |
| HOST=`hostname` | |
| echo "update delete $HOST A" > /var/nsupdate.txt | |
| echo "update add $HOST 86400 A $ADDR" >> /var/nsupdate.txt | |
| echo "update delete $HOST PTR" > /var/nsupdate.txt | |
| echo "update add $HOST 86400 PTR $ADDR" >> /var/nsupdate.txt | |
| nsupdate /var/nsupdate.txt |
I'm loving this Unix-y version without needing a temporary file that can check your domain (if machine is domain joined) and update the domain's DNS server ad hoc say if your sssd.conf had been missing ad_hostname when you don't use the FQDN as the hostname.
ipaddress=$(hostname -i)
arpa=$(printf 'arpa.in-addr.%s.' "$ipaddress" | tac -s.)
fqdn=$(hostname -f).
mydnsserver=$(nslookup -type=soa $(hostname -d) | grep origin | awk -F'= ' '{print $2}')
echo "server $mydnsserver
update add $fqdn 3600 IN A $ipaddress
send
update add $arpa 3600 IN PTR $fqdn
send
quit
" | nsupdate
Add -d and -D after nsupdate to get a really verbose listing of what it is doing as it updates.
Hey I don't know if this is related but I need nsupdate to be one line for a specific use case is this possible?
Hey I don't know if this is related but I need nsupdate to be one line for a specific use case is this possible?
It depends on what you define as 'one line'. The nsupdate commands (update add ...) have to be on separate lines, i.e. they are newline delimited. You could use the printf command to have it as a single line and use '\n' newline character where needed, but it gets ugly:
ipaddress=$(hostname -i); arpa=$(printf 'arpa.in-addr.%s.' "$ipaddress" | tac -s.); fqdn=$(hostname -f).; mydnsserver=$(nslookup -type=soa $(hostname -d) | grep origin | awk -F'= ' '{print $2}'); printf "server $mydnsserver\nupdate add $fqdn 3600 IN A $ipaddress\nsend\nupdate add $arpa 3600 IN PTR $fqdn\nsend\nquit\n" | nsupdateI haven't tested this btw, but the general structure should work. Remove the | nsupdate to check the syntax.
Thought I would provide an update for my own sanity: