Elektra
0.9.2
|
The /etc/hosts
file is a simple text file that associates IP addresses with hostnames, one line per IP address. The format is described in 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 /doc/METADATA.ini for more information).
The ordering of the hosts is stored in metakeys of type order
. The value is an ascending number. Ordering of aliases is not preserved.
Mount the plugin:
Print out all known hosts and their aliases:
Get IP address of ipv4 host "localhost":
Check if a comment is belonging to host "localhost":
Try to change the host "localhost", should fail because it is not an IPv4 address:
```
sudo kdb mount –with-recommends hosts /tests/hosts hosts
echo '127.0.0.1 localhost' > kdb file /tests/hosts
echo '::1 localhost' >> kdb file /tests/hosts
cat kdb file /tests/hosts
#> 127.0.0.1 localhost #> ::1 localhost
kdb get /tests/hosts/ipv4/localhost #> 127.0.0.1 kdb get /tests/hosts/ipv6/localhost #> ::1
kdb set /tests/hosts/ipv4/localhost ::1
kdb set /tests/hosts/ipv6/localhost 127.0.0.1
kdb rm -r /tests/hosts sudo kdb umount /tests/hosts ```