
\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)}.

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

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

Comments are stored according to the comment metadata specification (see \href{/home/jenkins/workspace/libelektra_master-Q2SIBK3KE2NBEMJ4WVGJXAXCSCB77DUBUULVLZDKHQEV3WNDXBMA/doc/METADATA.ini}{\tt /doc/\+M\+E\+T\+A\+D\+A\+TA.ini} for more information).

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.

Mount the plugin\+:


\begin{DoxyCode}
sudo kdb mount --with-recommends /etc/hosts system/hosts hosts
\end{DoxyCode}


Print out all known hosts and their aliases\+:


\begin{DoxyCode}
kdb ls system/hosts
\end{DoxyCode}


Get IP address of ipv4 host \char`\"{}localhost\char`\"{}\+:


\begin{DoxyCode}
kdb get system/hosts/ipv4/localhost
\end{DoxyCode}


Check if a comment is belonging to host \char`\"{}localhost\char`\"{}\+:


\begin{DoxyCode}
kdb lsmeta system/hosts/ipv4/localhost
\end{DoxyCode}


Try to change the host \char`\"{}localhost\char`\"{}, should fail because it is not an I\+Pv4 address\+:


\begin{DoxyCode}
sudo kdb set system/hosts/ipv4/localhost ::1
\end{DoxyCode}


``` \hypertarget{autotoc_md300_autotoc_md307}{}\section{Backup-\/and-\/\+Restore\+:/tests/hosts}\label{autotoc_md300_autotoc_md307}
sudo kdb mount --with-\/recommends hosts /tests/hosts hosts\hypertarget{autotoc_md300_autotoc_md308}{}\section{Create hosts file for testing}\label{autotoc_md300_autotoc_md308}
echo \textquotesingle{}127.\+0.\+0.\+1 localhost\textquotesingle{} $>$ {\ttfamily kdb file /tests/hosts} echo \textquotesingle{}\+:\+:1 localhost\textquotesingle{} $>$$>$ {\ttfamily kdb file /tests/hosts}\hypertarget{autotoc_md300_autotoc_md309}{}\section{Check the file}\label{autotoc_md300_autotoc_md309}
cat {\ttfamily kdb file /tests/hosts} \#$>$ 127.\+0.\+0.\+1 localhost \#$>$ \+:\+:1 localhost\hypertarget{autotoc_md300_autotoc_md310}{}\section{Check if the values are read correctly}\label{autotoc_md300_autotoc_md310}
kdb get /tests/hosts/ipv4/localhost \#$>$ 127.\+0.\+0.\+1 kdb get /tests/hosts/ipv6/localhost \#$>$ \+:\+:1\hypertarget{autotoc_md300_autotoc_md311}{}\section{Should both fail with error 04200 and return 5}\label{autotoc_md300_autotoc_md311}
kdb set /tests/hosts/ipv4/localhost \+:\+:1 \hypertarget{autotoc_md300_autotoc_md312}{}\section{R\+E\+T\+:5}\label{autotoc_md300_autotoc_md312}
\hypertarget{autotoc_md300_autotoc_md313}{}\section{E\+R\+R\+O\+R\+:\+C03200}\label{autotoc_md300_autotoc_md313}
kdb set /tests/hosts/ipv6/localhost 127.\+0.\+0.\+1 \hypertarget{autotoc_md300_autotoc_md314}{}\section{R\+E\+T\+:5}\label{autotoc_md300_autotoc_md314}
\hypertarget{autotoc_md300_autotoc_md315}{}\section{E\+R\+R\+O\+R\+:\+C03200}\label{autotoc_md300_autotoc_md315}
\hypertarget{autotoc_md300_autotoc_md316}{}\section{cleanup}\label{autotoc_md300_autotoc_md316}
kdb rm -\/r /tests/hosts sudo kdb umount /tests/hosts ``` 