
\begin{DoxyItemize}
\item infos = Information about hosts plugin is in keys below
\item infos/author = Markus Raab \href{mailto:elektra@libelektra.org}{\tt elektra@libelektra.\+org}
\item infos/licence = B\+SD
\item infos/provides = storage/hosts
\item infos/needs =
\item infos/recommends = glob error network
\item infos/placements = getstorage setstorage
\item infos/status = maintained unittest nodep libc limited
\item infos/metadata = order comment/\# comment/\#/start comment/\#/space
\item infos/description = This plugin reads and writes /etc/hosts files.
\end{DoxyItemize}

The {\ttfamily /etc/hosts} file is a simple text file that associates IP addresses with hostnames, one line per IP address. The format is described in {\ttfamily hosts(5)}.

\subsection*{Special values}

\subsubsection*{Hostnames}

Canonical hostnames are stored as key names with their IP address as value.

\subsubsection*{Aliases}

Aliases are stored as sub keys with a read only duplicate of the associated IP address as value.

\subsubsection*{Comments}

Comments are stored according to the comment metadata specification (see \href{/home/markus/Projekte/Elektra/current/doc/METADATA.ini}{\tt /doc/\+M\+E\+T\+A\+D\+A\+TA.ini} for more information).

\subsubsection*{Ordering}

The ordering of the hosts is stored in metakeys of type {\ttfamily order}. The value is an ascending number. Ordering of aliases is {\itshape not} preserved.

\subsection*{Examples}

Mount the plugin\+: \begin{DoxyVerb}$ sudo kdb mount --with-recommends /etc/hosts system/hosts hosts
\end{DoxyVerb}


Print out all known hosts and their aliases\+: \begin{DoxyVerb}$ kdb ls system/hosts
\end{DoxyVerb}


Get IP address of ipv4 host \char`\"{}localhost\char`\"{}\+: \begin{DoxyVerb}$ kdb get system/hosts/ipv4/localhost
\end{DoxyVerb}


Check if a comment is belonging to host \char`\"{}localhost\char`\"{}\+: \begin{DoxyVerb}$ kdb lsmeta system/hosts/ipv4/localhost
\end{DoxyVerb}


Try to change the host \char`\"{}localhost\char`\"{}, should fail because it is not an I\+Pv4 address\+: \begin{DoxyVerb}$ sudo kdb set system/hosts/ipv4/localhost ::1
\end{DoxyVerb}


``` \section*{Backup-\/and-\/\+Restore\+:/examples/hosts}

sudo kdb mount --with-\/recommends hosts /examples/hosts hosts

\section*{Create hosts file for testing}

echo \textquotesingle{}127.\+0.\+0.\+1 localhost\textquotesingle{} $>$ {\ttfamily kdb file /examples/hosts} echo \textquotesingle{}\+:\+:1 localhost\textquotesingle{} $>$$>$ {\ttfamily kdb file /examples/hosts}

\section*{Check the file}

cat {\ttfamily kdb file /examples/hosts} \#$>$ 127.\+0.\+0.\+1 localhost \#$>$ \+:\+:1 localhost

\section*{Check if the values are read correctly}

kdb get /examples/hosts/ipv4/localhost \#$>$ 127.\+0.\+0.\+1 kdb get /examples/hosts/ipv6/localhost \#$>$ \+:\+:1

\section*{Should both fail with error 51 and return 5}

kdb set /examples/hosts/ipv4/localhost \+:\+:1 \section*{R\+ET\+:5}

\section*{E\+R\+R\+OR\+:51}

kdb set /examples/hosts/ipv6/localhost 127.\+0.\+0.\+1 \section*{R\+ET\+:5}

\section*{E\+R\+R\+OR\+:51}

\section*{cleanup}

kdb rm -\/r /examples/hosts sudo kdb umount /examples/hosts ``` 