Gerymake
Posts: 41
Joined: Sun Jan 06, 2019 11:38 pm

Connecting to several PI in the same network

Fri May 24, 2019 5:24 pm

Hello,

I guess this must have been answered but I'm not sure how to find it. 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. Therefore, how can I set up a durable method? Furthermore, I need to connect from Putty to those so I should have an invariable host name.

Thanks,

PhatFil
Posts: 1305
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Connecting to several PI in the same network

Fri May 24, 2019 6:25 pm

look at setting static ip addresses either by reserving ip addresses at your router/dhcp server or if not an available feature https://www.modmypi.com/blog/how-to-giv ... ess-update.

Andyroo
Posts: 3756
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Connecting to several PI in the same network

Fri May 24, 2019 7:11 pm

Remember to use

Code: Select all

sudo raspi-config
Options 2 / N1 to change the host name on each pi.

Normally I would say you cannot have too much raspberrypi(.local) but more than one can lead to odd networking issues :lol:
Need Pi spray - these things are breeding in my house...

dl324
Posts: 122
Joined: Mon May 06, 2019 7:33 pm
Location: Pacific Northwest, USA

Re: Connecting to several PI in the same network

Fri May 24, 2019 8:05 pm

Gerymake wrote:
Fri May 24, 2019 5:24 pm
I tried using the private IP address from (hostname -I) but it may change when disconnected or rebooted. Therefore, how can I set up a durable method? Furthermore, I need to connect from Putty to those so I should have an invariable host name.
You control the hostnames. Your DHCP server assigns IP addresses and they should be the same each time the device connects to the network.

To connect by hostname from Windows, you need to put the hostnames and their IP addresses in C:\WINDOWS\system32\drivers\etc\hosts. Otherwise, you'll need to use IP addresses. That isn't much of a bother because you can save sessions in the PuTTy app.

epoch1970
Posts: 3319
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Connecting to several PI in the same network

Fri May 24, 2019 8:54 pm

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.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Andyroo
Posts: 3756
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Connecting to several PI in the same network

Fri May 24, 2019 10:00 pm

dl324 wrote:
Fri May 24, 2019 8:05 pm
Gerymake wrote:
Fri May 24, 2019 5:24 pm
I tried using the private IP address from (hostname -I) but it may change when disconnected or rebooted. Therefore, how can I set up a durable method? Furthermore, I need to connect from Putty to those so I should have an invariable host name.
You control the hostnames. Your DHCP server assigns IP addresses and they should be the same each time the device connects to the network.

To connect by hostname from Windows, you need to put the hostnames and their IP addresses in C:\WINDOWS\system32\drivers\etc\hosts. Otherwise, you'll need to use IP addresses. That isn't much of a bother because you can save sessions in the PuTTy app.
Bad practise to add names into host files - it will bite you one day :D when you miss an entry or get one wrong.

It’s a lot better to use the .local domain as this is supported by Macs by default, PCs with either Apple Bonjour (part of iTunes or a separate load) or updated Windows 10, Linux boxes with Avahi and anything else that supports mDNS

There is a long running ‘discussion’ amongst the internet naming groups over local and home extensions that no one will make their mind up on as it could break lots and lots but there is lots for £$€¥ involved by selling rights to use it...
Need Pi spray - these things are breeding in my house...

epoch1970
Posts: 3319
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Connecting to several PI in the same network

Fri May 24, 2019 11:08 pm

dl324 wrote:
Fri May 24, 2019 8:05 pm
... you need to put the hostnames and their IP addresses in C:\WINDOWS\system32\drivers\etc\hosts. Otherwise, you'll need to use IP addresses....
??
Don't use hosts anyway. But it cannot help here at all.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Beginners”