Linux/DNS: Difference between revisions

From Omnia
Jump to navigation Jump to search
 
 
Line 1: Line 1:
== Linux DNS ==
== Linux DNS Lookup ==


Host lookup:
Host lookup:
  host www.google.com
  host www.google.com
  host 4.2.2.2
  host 4.2.2.2 # Reverse Lookup


Dig Host lookup:
Dig Host lookup:
  dig www.google.com
  dig www.google.com
  dig -x 4.2.2.2
  dig -x 4.2.2.2 # Reverse Lookup


Use DNS cachse
NSLookup:
  service nscd start
  nslookup www.google.com
nslookup 4.2.2.2  # Reverse Lookup
 
GetENT Lookup:
getent hosts www.google.com
getent hosts 4.2.2.2  # Reverse Lookup


Clear DNS cache:
# Name Service Switch (NSS) based Resolution:
  service nscd restart
  # getent: This command displays entries from databases supported by the Name Service Switch libraries, configured in /etc/nsswitch.conf. It can resolve hostnames based on various sources, including /etc/hosts and DNS.


Resolve an IP that may be in /etc/hosts or DNS: (part of MySQL Server package)
Resolve an IP that may be in /etc/hosts or DNS: (part of MySQL Server package)
Line 20: Line 25:
nametoip or whatip: (Python script)
nametoip or whatip: (Python script)
* See [[Python#Convert hostname to ip address]]
* See [[Python#Convert hostname to ip address]]
== Linux DNS Cache ==
Use DNS cache
service nscd start
Clear DNS cache:
service nscd restart


== Bind DNS Server ==
== Bind DNS Server ==

Latest revision as of 19:52, 23 October 2025

Linux DNS Lookup

Host lookup:

host www.google.com
host 4.2.2.2  # Reverse Lookup

Dig Host lookup:

dig www.google.com
dig -x 4.2.2.2  # Reverse Lookup

NSLookup:

nslookup www.google.com
nslookup 4.2.2.2  # Reverse Lookup

GetENT Lookup:

getent hosts www.google.com
getent hosts 4.2.2.2  # Reverse Lookup
# Name Service Switch (NSS) based Resolution:
# getent: This command displays entries from databases supported by the Name Service Switch libraries, configured in /etc/nsswitch.conf. It can resolve hostnames based on various sources, including /etc/hosts and DNS. 

Resolve an IP that may be in /etc/hosts or DNS: (part of MySQL Server package)

/usr/bin/resolveip -s [HOSTNAME]

nametoip or whatip: (Python script)

Linux DNS Cache

Use DNS cache

service nscd start

Clear DNS cache:

service nscd restart

Bind DNS Server

See BIND

Dynamic DNS

nsupdate

server 10.50.10.74
update add 
send
quite

References:

FIO Solution

/tmp/nsupdate.txt

server 10.50.10.74
update delete fb-uefi-8.oeey.com A
update add fb-uefi-8.oeey.com 86400 IN A 10.50.143.58
update delete fb-uefi-08.oeey.com A
update add fb-uefi-08.oeey.com 86400 IN A 10.50.143.58
send
update add 58.143.50.10.in-addr.arpa 86400 PTR fb-uefi-8.oeey.com
send
server 10.50.10.75
update delete fb-uefi-8.oeey.com A
update add fb-uefi-8.oeey.com 86400 IN A 10.50.143.58
update delete fb-uefi-08.oeey.com A
update add fb-uefi-08.oeey.com 86400 IN A 10.50.143.58
send
update add 58.143.50.10.in-addr.arpa 86400 PTR fb-uefi-8.oeey.com
send
quit

Delete ptr:

# nsupdate
server 10.50.10.74
update delete 84.44.50.10.in-addr.arpa 86400 PTR esx1-bench.oeey.com.
send
server 10.50.10.75
update delete 84.44.50.10.in-addr.arpa 86400 PTR esx1-bench.oeey.com.
send
quit

cron:

30 2 * * * /usr/local/bin/DDNSupdate.sh

/usr/local/bin/DDNSupdate.sh:

#!/bin/bash
DOMAIN=int.oeey.com
NAMESERVERS="10.50.10.74 10.50.10.75"

if [[ $1 == "" || $2 == "" ]]; then
  echo "Usage: $0 <ip> <hostname1> [name2] [name3] [name4]"
  exit 1
fi

#let's break down the IP so we can make a reverse lookup record
oct1=$(echo $1 | cut -d\. -f1)
oct2=$(echo $1 | cut -d\. -f2)
oct3=$(echo $1 | cut -d\. -f3)
oct4=$(echo $1 | cut -d\. -f4)
reverseEntry=$(echo "$oct4.$oct3.$oct2.$oct1.in-addr.arpa")

> nsupdate.txt

for NAMESERVER in $NAMESERVERS ; do
echo "server $NAMESERVER" >> nsupdate.txt
echo "update delete $2.$DOMAIN A" >> nsupdate.txt
echo "update add $2.$DOMAIN 86400 IN A $1" >> nsupdate.txt
if [ $3 ]; then
echo "update delete $3.$DOMAIN A" >> nsupdate.txt
echo "update add $3.$DOMAIN 86400 IN A $1" >> nsupdate.txt
fi
if [ $4 ]; then
echo "update delete $4.$DOMAIN A" >> nsupdate.txt
echo "update add $4.$DOMAIN 86400 IN A $1" >> nsupdate.txt
fi
if [ $5 ]; then
echo "update delete $5.$DOMAIN A" >> nsupdate.txt
echo "update add $5.$DOMAIN 86400 IN A $1" >> nsupdate.txt
fi
echo "send" >> nsupdate.txt
echo "update add $reverseEntry 86400 PTR $2.$DOMAIN" >> nsupdate.txt
echo "send" >> nsupdate.txt
done

echo "quit" >> nsupdate.txt
#cat nsupdate.txt

echo "Updating $1 with $2.$DOMAIN $3 $4 $5"
nsupdate nsupdate.txt
rm -f nsupdate.txt

/usr/local/bin/updateNS.sh (OLD)

#!/bin/bash
if [[ $1 != "" && $2 != "" ]]; then
#let's break down the IP so we can make a reverse lookup record
oct1=$(echo $1 | cut -d\. -f1)
oct2=$(echo $1 | cut -d\. -f2)
oct3=$(echo $1 | cut -d\. -f3)
oct4=$(echo $1 | cut -d\. -f4)
reverseEntry=$(echo "$oct4.$oct3.$oct2.$oct1.in-addr.arpa")

echo "server 10.50.10.74" > /tmp/nsupdate.txt
echo "update delete $2.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $2.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
if [ $3 ]; then
echo "update delete $3.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $3.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
fi
if [ $4 ]; then
echo "update delete $4.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $4.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
fi
if [ $5 ]; then
echo "update delete $5.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $5.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
fi
echo "send" >> /tmp/nsupdate.txt
echo "update add $reverseEntry 86400 PTR $2.oeey.com" >> /tmp/nsupdate.txt
echo "send" >> /tmp/nsupdate.txt

echo "server 10.50.10.75" >> /tmp/nsupdate.txt
echo "update delete $2.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $2.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
if [ $3 ]; then
echo "update delete $3.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $3.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
fi
if [ $4 ]; then
echo "update delete $4.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $4.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
fi
if [ $5 ]; then
echo "update delete $5.oeey.com A" >> /tmp/nsupdate.txt
echo "update add $5.oeey.com 86400 IN A $1" >> /tmp/nsupdate.txt
fi
echo "send" >> /tmp/nsupdate.txt
echo "update add $reverseEntry 86400 PTR $2.oeey.com" >> /tmp/nsupdate.txt
echo "send" >> /tmp/nsupdate.txt
echo "quit" >> /tmp/nsupdate.txt
#cat /tmp/nsupdate.txt
nsupdate /tmp/nsupdate.txt
fi

/usr/local/bin/removeNS.sh:

#!/bin/bash
if [[ $1 != "" && $2 != "" ]]; then
#let's break down the IP so we can make a reverse lookup record
oct1=$(echo $1 | cut -d\. -f1)
oct2=$(echo $1 | cut -d\. -f2)
oct3=$(echo $1 | cut -d\. -f3)
oct4=$(echo $1 | cut -d\. -f4)
reverseEntry=$(echo "$oct4.$oct3.$oct2.$oct1.in-addr.arpa")

echo "server 10.50.10.74" > /tmp/nsupdate.txt
echo "update delete $2.oeey.com A" >> /tmp/nsupdate.txt
if [ $3 ]; then
echo "update delete $3.oeey.com A" >> /tmp/nsupdate.txt
fi
if [ $4 ]; then
echo "update delete $4.oeey.com A" >> /tmp/nsupdate.txt
fi
if [ $5 ]; then
echo "update delete $5.oeey.com A" >> /tmp/nsupdate.txt
fi
echo "send" >> /tmp/nsupdate.txt
#echo "update delete $reverseEntry PTR" >> /tmp/nsupdate.txt
echo "update delete $reverseEntry PTR $2.oeey.com" >> /tmp/nsupdate.txt
echo "send" >> /tmp/nsupdate.txt

echo "server 10.50.10.75" >> /tmp/nsupdate.txt
echo "update delete $2.oeey.com A" >> /tmp/nsupdate.txt
if [ $3 ]; then
echo "update delete $3.oeey.com A" >> /tmp/nsupdate.txt
fi
if [ $4 ]; then
echo "update delete $4.oeey.com A" >> /tmp/nsupdate.txt
fi
if [ $5 ]; then
echo "update delete $5.oeey.com A" >> /tmp/nsupdate.txt
fi
echo "send" >> /tmp/nsupdate.txt
#echo "update delete $reverseEntry PTR" >> /tmp/nsupdate.txt
echo "update delete $reverseEntry PTR $2.oeey.com" >> /tmp/nsupdate.txt
echo "send" >> /tmp/nsupdate.txt
echo "quit" >> /tmp/nsupdate.txt
#cat /tmp/nsupdate.txt
nsupdate /tmp/nsupdate.txt
fi

TO READ

Linux DNS: