Gerymake wrote: ↑
Fri May 24, 2019 5:24 pm
I have several Pi in the same network which ought to connect to a DB (installed in one of those Pi). I tried using the private IP address from (hostname -I) but it may change when disconnected or rebooted.
That is what domain names are for. Names stay put when addresses change.
The hostname is often used to locate a machine, e.g. "raspberrypi.mynet.", but you can also define aliases (CNAMEs) so that the machine running your service is also reachable at, e.g. "mydatabase.mynet."
If you want to provide extra details besides a resolvable IP address, you can also use TXT records
to publish a service description.
Hostname, aliases, service records can be used with DNS or with mDNS. The Internet is built upon a hierarchy of DNS domains and servers. mDNS is its peer-to-peer (no central server), multicast, local network only, version.
Raspbian comes with Avahi in order to provide mDNS. If you want to install a DNS server, dnsmasq is simple and will allow to do all of the above, and more. In general mDNS is easier to setup and use than DNS.