meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 6:26 am

Hi all,

here is my problem. I have a Rpi 2. I've set up a LAMP. I would like to be able to plug my Rpi to other routeurs, not only mine. That means that its IP will change. So, how can someone that want to connect to my Rpi with its smartphone could know my Rpi IP address? Is there a way for the smartphone to automatically connect to the Rpi/apache index.php page?

I've been thinking about setting a static IP. The problem is that if I set my Rpi IP to, let's say 192.168.0.100, and the routeur to 192.168.0.1, but there is a problem if a plug in a new routeur with an address like 192.168.1.1.

I've also been thinking about changing the IP address by a name like myraspberry.lan but I couldn't find how. I tried Avahi but it doesn't work when I try to connect to my Rpi using Windows (even with Bonjour and Itunes install), and it doesn't work with Android, so it's not the best solution...

If you have any idea, it would be great!

Thanks a lot

meazfpc

Adolfo.Abalia
Posts: 41
Joined: Thu Apr 07, 2016 9:29 am
Location: Madrid, Spain

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 9:33 am

For the last of your concerns, you can use some free DNS service (like the ones listed here: http://www.makeuseof.com/tag/5-best-dyn ... ree-today/) You will need some sort of client to update public IP to the DNS server of your choice (see this: http://blog.mivia.dk/free-dynamic-dns-for-raspberry-pi/ or https://2ellsblog.wordpress.com/2016/02 ... ngeip-com/)

This would solve the problem of having your RPi reachable with a human readable URL, but you still need to do some NAT tasks for it to be open, I guess.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 9:40 am

As an alternative that side-steps this issue of changing private and public IP addresses, have you thought of using one of the "RPi phone home" services such as Weaved, Wyliodrin or Dataplicity?

An element of trust in a third-party is involved, so this is only a suggestion not a recommendation.

meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 10:03 am

My raspberry is not connected to internet, the routeur creates a wifi local network. But no internet access.

Thanks anyway!

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 10:08 am

Equip the RPi with a WiFi dongle, and configure it as its own wireless access point?

meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 11:07 am

Hi,

Thank a lot for your answer but it's not satisfactory as a dongle can't handle a lot of connection whereas a good router.

Best

Meazfpc

Adolfo.Abalia
Posts: 41
Joined: Thu Apr 07, 2016 9:29 am
Location: Madrid, Spain

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 11:15 am

So, the scenario is something like this: you plug your RPi to one or more routers (not open to the internet) and you want to get to it from inside the LAN , correct?

What I do to discover "where" my RPi is on the LAN is to launch a nmap search for port 22 (for ssh) and find the device name on the list. Then I can "ssh" it. It gets easier if the RPi is the only one listening at 22.

P.S: you can change 22 with the port number of your choice (80, 8080 or whatever service it runs)

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

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 11:21 am

Speak (TTS) the address over and over via the headphone plug?
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 11:25 am

I use samba for file sharing:

Code: Select all

sudo apt-get install samba
Even if you don't setup any shares, that should make the pi discoverable by hostname
Android app - Raspi Card Imager - download and image SD cards - No PC required !

Romonga
Posts: 123
Joined: Mon May 09, 2016 7:09 pm
Location: Montgomery Il

Re: How to get the Rpi IP when the router changes often?

Mon Jun 20, 2016 11:47 am

Seems that if you are trying to access the Pi on the local network side of any router the simplest thing would be to give the Pi a proper name.

I never have to worry about what IP address my Pi has, because I access it by host name.

ProtoPi.local
RomoPi.local
SmartOne.local

....
https://thepihut.com/blogs/raspberry-pi ... e-hostname
You can run, but you will only die tired.

meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 9:13 am

Adolfo.Abalia wrote:So, the scenario is something like this: you plug your RPi to one or more routers (not open to the internet) and you want to get to it from inside the LAN , correct?

What I do to discover "where" my RPi is on the LAN is to launch a nmap search for port 22 (for ssh) and find the device name on the list. Then I can "ssh" it. It gets easier if the RPi is the only one listening at 22.

P.S: you can change 22 with the port number of your choice (80, 8080 or whatever service it runs)
Hi Adolfo,

thanks for your message. However, the goal is to have people that don't really know anything about ICT be able to connect easily. And to do it on a smartphone or a tablet. So having them to use nmap seems to hard.

Best

meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 9:14 am

epoch1970 wrote:Speak (TTS) the address over and over via the headphone plug?
Hi epoch1970,

I don't understand what you suggest, sorry. Could you explain more in details?

Best

meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 9:17 am

Romonga wrote:Seems that if you are trying to access the Pi on the local network side of any router the simplest thing would be to give the Pi a proper name.

I never have to worry about what IP address my Pi has, because I access it by host name.

ProtoPi.local
RomoPi.local
SmartOne.local

....
https://thepihut.com/blogs/raspberry-pi ... e-hostname
Hi Romonga,

I've already tried that. However, when I try to access myraspberry.local, it does work from my iPhone, but not from my windows 10 laptop, neither from an Android smartphone. I would prefer something more universal.

Best

meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 9:19 am

mikerr wrote:I use samba for file sharing:

Code: Select all

sudo apt-get install samba
Even if you don't setup any shares, that should make the pi discoverable by hostname
Hi Mike,

thanks for the idea, I'm going to try that! So I just install samba and that's it?!

best

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

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 9:39 am

meazfpc wrote:
epoch1970 wrote:Speak (TTS) the address over and over via the headphone plug?
Hi epoch1970,

I don't understand what you suggest, sorry. Could you explain more in details?

Best
On some headless servers, I have used text-to-speech software to provide system feedback in absence of any other UI: "a short press on the button, then the computer will speak its IP address" or "plug the headphones in, the computer speaks the IP address every 30 seconds"
It's funny as hell to setup, but in fact it's mildly successful with end users.

I haven't done that in a while (and never on a Pi). This is what I recall: I think espeak is good in the sense it works more or less out-of-the box. Mbrola is good in the sense it offers great speech quality for various languages beyond english. Festival is (was) everywhere because it was one of the first projects around, but not so good I think. Svox was besting espeak last time around (now part of Nuance, don't know if the open source software is still alive)
Of course it's 2016 now so I'm sure you can get amazing TTS services over the internet. I would also look at the TTS technology VOIP systems (like Asterisk) use, they are certainly aiming for speed and quality.

One last thing: don't try using the linux-for-the-bind features. I thought once it was a good idea to use a system-level TTS interface, but in fact its purpose is different. The system speaks very, very, really, very fast and quality comes second. It doesn't work at all with untrained ears.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Adolfo.Abalia
Posts: 41
Joined: Thu Apr 07, 2016 9:29 am
Location: Madrid, Spain

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 9:48 am

Ok, we are just guessing :) I think your only possibility is what @B.Goode pointed out: using some sort of "phone home" service (or script) so when the RPi boots will start broadcasting.

I've asked some workmates and they've told me to investigate MDNS and avahi. Give it a try.

You might also use a very simple LCD display to show the device's IP once it gets one (a lot less funny variant of @epoch1970 solution :))

Romonga
Posts: 123
Joined: Mon May 09, 2016 7:09 pm
Location: Montgomery Il

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 1:51 pm

meazfpc wrote:
Romonga wrote:Seems that if you are trying to access the Pi on the local network side of any router the simplest thing would be to give the Pi a proper name.

I never have to worry about what IP address my Pi has, because I access it by host name.

ProtoPi.local
RomoPi.local
SmartOne.local

....
https://thepihut.com/blogs/raspberry-pi ... e-hostname
Hi Romonga,

I've already tried that. However, when I try to access myraspberry.local, it does work from my iPhone, but not from my windows 10 laptop, neither from an Android smartphone. I would prefer something more universal.

Best

that is an interesting comment considering the naming schema I suggested is universal. Let me ask, when attempting from your Android smart phone was it connected to your local network?
You can run, but you will only die tired.

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

Re: How to get the Rpi IP when the router changes often?

Thu Jun 23, 2016 2:11 pm

Romonga wrote:that is an interesting comment considering the naming schema I suggested is universal.
Mhh. Wasn't universal before it was invented, was it?
Plenty of machines still don't grok mDNS by default, even today. Does out-of-the-box Raspian come with mDNS and autoipv4ll ? I think I've added avahi or avahi-autoipd.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

meazfpc
Posts: 9
Joined: Mon Jun 20, 2016 6:18 am

Re: How to get the Rpi IP when the router changes often?

Sat Jun 25, 2016 7:20 am

Thanks a lot to all of you. I'll try that as soon as I find some time! And I'll get back to you.

Best

User avatar
bensimmo
Posts: 4622
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: How to get the Rpi IP when the router changes often?

Sat Jun 25, 2016 8:01 am

I have no idea, I've not tried to name the Pi other than in raspi-config.

But on android I use Fing to scan through the network and it's easy to pick the Pi's out and then scan ports and launch day from there.

But it's not going to help you for universal appeal.

How do the two Raspixxx RaspiCam and RaspiSomthing else on Android scan to find Pi's?

Could you need build a scan into you program and look for Pi signatures (Macs, Pi names in the set name?)
Could you add an LCD screen and just display the IP address?

That's me done, cross platform networking is not a lot I know about, though will try what works for you (as we access them from iOS, Android and Windows)

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: How to get the Rpi IP when the router changes often?

Sat Jun 25, 2016 4:34 pm

meazfpc wrote:I've been thinking about setting a static IP. The problem is that if I set my Rpi IP to, let's say 192.168.0.100, and the routeur to 192.168.0.1, but there is a problem if a plug in a new routeur with an address like 192.168.1.1.
Then have the system set its static ip address to a specific and known but unlikely to be used part of the subnet, say Whatever Dot 76 . When it's on your network, it would be at 192.168.0.76 and when it's on Bob's network, it would be at 192.168.2.76 . So all you need to access it is knowledge of which subnet is being used, which you can get from the dhcp server or by running ifconfig on any linux machine or ipconfig on a windows machine or by running fing on an android device.

You could also check Whatever Dot 76 on the new network to see if someone else is there and then use a known back up, how about Whatever Dot 176 ? Using this, you'd have a solution for almost all home type networks out there, I would bet.

You can also use fping in a script to get general information for what is going on and put this and other data into a local web server at the address and back up address you are using.

If you are headless, it can be nice to access the machine from any box running a web browser and on the network, something that you should be able to set up with shellinabox, which is in the repositories.

You'll probably also want to bring a usb thumb drive with software on it (even though the idea is to never really need it) although protecting it from potentially getting some sort of virus might be challenging. Perhaps some scheme for checking the drive on a linux box after its use and having some place on the drive the files stored in a way that a virus probably can't figure out. One program that can be useful is MobaXterm which should be available directly form the developers and not from some spyware laced site, well, it is surely available from the latter like all Windows stuff.

And while you don't need it here, it is also true that you can transfer small amounts of data via the ping command. What this means isn't just that if you compromised a certain presidential candidate's e-mail server but could only ping out, you'd still have a solution, it also means that less nefarious uses are potentially possible, such as using ping to send the ip address of a box even though the box can only ping out. I don't know if some routers automatically filter this data, but I think they absolutely should!

Return to “General discussion”