\section{DNS and Name Resolution}

\begin{frame}
   {DNS and Name Resolution}

   \begin{itemize}
      \item Name resolution: converting a hostname to an IP
      address
      \begin{itemize}
         \item Static name resolution
         \item Dynamic name resolution (\textbf{DNS})
      \end{itemize}
      \item Reverse resolution: converting an IP address to a
      hostname
      \item From the command line:
      \begin{cmd}
$ dig linuxfoundation.org
$ host linuxfoundation.org
$ nslookup linuxfoundation.org
      \end{cmd}
   \end{itemize}

\end{frame}

\cprotect\note{

   \textbf{Name resolution} is the act of translating
   hostnames to the IP addresses of their hosts.

   For example, a browser or email client will take
   \texttt{training.linuxfoundation.org} and resolve the
   name to the IP address of the server (or servers) that
   serve \texttt{training.linuxfoundation.org} in order to
   transmit to and from that location.

   This can be done in either \textbf{static} fashion, using
   \filelink{/etc/hosts}), or dynamically using \textbf{DNS}
   servers).

   There are several command line tools that can be used
   to resolve the IP address of a hostname:
   \begin{itemize}
      \item \textbf{dig}: generates the most information and has many options
      \item \textbf{host}: more compact
      \item \textbf{nslookup}: older
   \end{itemize}
   \textbf{dig} is newest and the other are sometimes
   considered deprecated, but the output for \textbf{host}
   is easiest to read and contains the basic information.

   One sometimes also requires \textbf{reverse resolution}:
   converting an IP address to a hostname.  Try feeding these 3
   utilities a known IP address instead of a hostname,
   and examine the output.
}
\begin{frame}
   {/etc/hosts}

   \begin{itemize}
      \item Used for local or static hostname resolution
      \item Useful for small isolated networks
      \item Usually checked before DNS
      \item Priority can be configured under
      \filelink{/etc/nsswitch.conf} but not often used
      today
      \begin{cmd}
student@ubuntu:/etc$ ls -l host*
      \end{cmd}
      \begin{response}
-rw-r--r-- 1 root root  92 Oct 22  2015 host.conf
-rw-r--r-- 1 root root   7 Apr 21 08:46 hostname
-rw-r--r-- 1 root root 221 Apr 21 08:46 hosts
-rw-r--r-- 1 root root 411 Apr 20 17:14 hosts.allow
-rw-r--r-- 1 root root 711 Apr 20 17:14 hosts.deny
      \end{response}
   \end{itemize}

\end{frame}

\cprotect\note{

   \filelink{/etc/hosts} holds a local database of
   hostnames and IP addresses.  It contains a set of
   records (each taking one line) which map IP addresses
   with corresponding hostnames and aliases.

   A typical \filelink{/etc/hosts} file looks like:

   \begin{configlst}[{/etc/hosts}]
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.100 hans hans7 hans64
192.168.1.150 bethe bethe7 bethe64
192.168.1.2 hp-printer
192.168.1.10 test32 test64 oldpc
   \end{configlst}

   Such static name resolution is primarily used for local,
   small, isolated networks.  It is generally checked
   before \textbf{DNS} is attempted to resolve an address;
   however, this priority can be controlled by
   \filelink{/etc/nsswitch.conf}, but is not often done today.

   The other host-related files in \filelink{/etc} are:

   \filelink{/etc/hosts.deny}, \filelink{/etc/hosts.allow}.

   These are self documenting and their purpose is obvious
   from their names.  The allow file is searched first and
   the deny file is only searched if the query is not found
   there.

   \filelink{/etc/host.conf} contains general configuration
   information; it is rarely used.

}

\begin{frame}
   {DNS}

   \begin{multicols}{2}
      \begin{itemize}
         \item Uses dynamic name servers
         \item \filelink{/etc/resolv.conf}
         \begin{itemize}
            \item Can specify particular domains to search.
            \item Defines a strict order of nameservers to query.
            \item May be manually configured or updated from a
            service such as \textbf{DHCP} (\textbf{D}ynamic
            \textbf{H}ost \textbf{C}onfiguration
            \textbf{P}rotocol).
         \end{itemize}
      \end{itemize}

      \begin{figure}[H]
         \includegraphics[height=3.2in]{IMAGES/DNS_zone}
         \caption{DNS}
      \end{figure}
   \end{multicols}
\end{frame}

\cprotect\note{

   If name resolution cannot be done locally using
   \filelink{/etc/hosts} then the system will query a
   \textbf{DNS} (\textbf{D}omain \textbf{N}ame
   \textbf{S}erver) server.

   \textbf{DNS} is dynamic and consists of a network of
   servers which a client uses to look up names.  The
   service is distributed; any one \textbf{DNS} server has
   only information about it's \textbf{zone of authority};
   however, all of them together can cooperate to resolve
   any name.

   The machine's usage of \textbf{DNS} is configured in
   \filelink{/etc/resolv.conf}, which historically has
   looked like:

   \begin{configlst}[{/etc/resolv.conf}]     
search example.com aps.org
nameserver 192.168.1.1
nameserver 8.8.8.8
   \end{configlst}
   However, most modern systems will have a \filelink{/etc/resolv.conf}
   file generated automatically, such as:
   \begin{cmd}
# Generated by NetworkManager
   \end{cmd}
   \begin{response}
  192.168.1.1
   \end{response}
   which was generated by \textbf{NetworkManager} invoking
   \textbf{DHCP} on the primary network interface.

}


