Notifications
Clear all

Howto NOT hard code ip addresses

47 Posts
4 Users
11 Likes
3,173 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee Thanks Dave, I will re-read that in  a moment, but I have an immediate problem.After setting the router dhcp to 192.168.0.2 to 192.168.0.99 and then assigning the PI4 mac to 192.168.0.100 I now have a PI4 that will not connect to the router.

I think I know why. I got the mac by doing an ifconfig wlan0 and the mac is right after the ip. I suspect the mac to ip binding only works on ethernet cable type connections, anf for wireless I have to put a static entry in the PI4 dhcpcd.conf file. Trying that now will let you know.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 
Posted by: @davee

So, thanks @Inq for your helpful reply above, which caused me to go and check some things. Of course, this does mean I have spent a few hours diverted from what I intended, but that is how research often works!

I know exactly what you mean... I SHOULD be out mowing the lawn, but I'm here, using this as an excuse to procrastinate.

Posted by: @davee

Inq correctly says:

"Howto NOT hard code ip addresses" - Most all routers I've seen will handle DNS capabilities within your LAN.  So if the computer name of your server is MyMQTTBrokeryou should be able to use the computer name instead of a hard-coded IP address. 

The trouble I had, is on first read, it didn't ring any bells on how to achieve it. Perhaps, I haven't been looking in the right places, but I have never seen it in the router set up manuals, etc.

Me either.  I have found no setting for it or descriptions.  I just "called" it a built-in DNS functionality for your LAN.  It's a whole lot easier to connect to our little MPU project servers with a name http://InqlingJr/Admin.html than having to go dig around for its IP address and do http://192.168.100.237/Admin.html that changes occasionally.  All the other DNS settings in the router are for Internet name resolution.

Posted by: @davee

I had noticed 'host name' before, but only used it as an identifier for my own purposes... it hadn't occurred to me it had any useful connection ... I am the only one who is so stupid? 🙄 🙄

Don't feel bad... for the longest time, the router I had did not support the local DNS capability and I had to use IP addresses.  When I got the above travel router and it supported this host name...   I ran over the old one a couple of times with the truck before taking it to the dump! 🙄 🤗 

Posted by: @davee

Thus if Gertrude, from the example above, wanted to call her local network, "glan", she could put "glan" in this box, and her server would be called gertrude-machine.glan for the purposes of ping, and presumably web, database, MQTT etc.

Hmmm... I'm going to have to try this out.  Didn't know this.

 

@davee - You write the best War and Peace posts around! 😍 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee Close. When I rebooted the PI it had no wifi and repeated clicking on the icon resulted in nada. I thn selected the wifi-5g option and voila it connected. I then changed the ssid on the laptop to be the 5g and now ping PI41.local WORKS!!!!

WHY is the 'normal' ssid not working? Should I edit the wpa-supplicant.conf file and completely delete the 5G entry?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi @zander and @Inq,

   Just a few follow up notes ... it took me a while to write the sermon, and by that time several messages had appeared!

-------------------------

  I am a little confused about the signal path you are trying to do. The simplest, which most homes probably do has just one router.

Internet connection <--> Router Wan Port --- Router Wifi 'port < --- > Client devices, incl ESP32

---

However, if the ESP32 is out of range of the 'main router's Wifi', then a repeater function is possible.

I don't have any direct experience of WiFi repeater .. so I have tried to look it up... hence ...

This repeater could be another router, set up to act as a repeater, or a 'specialised' device, such as a 'oversize mains plug with two aerials'. I think the specialised devices are usually simple 'plug and play; using a second router can be more tricky, though maybe cheaper if you already have one..

In either of the cases with a repeater, it seems the 'main router' does all the address handling, etc. in much the same way as when it talks to the ESP32 directly. That is the 'main router' settings are almost unchanged, for a particular config page to point to the repeater. It is not clear if all routers support such functionality. Similarly, the second router needs to be capable of setting up as repeater, which may not apply to all devices.

Lots of manual reading etc. seems to be obligatory for the two router case?

----------------------

Also from the picture, can I make any use of the 'Default Domain' and can I add a secondary DNS like a local RaspberryPi for 'local' name service?

I think my last message may have appropriate answers ... of course I am not familiar with your specific device ...

I think:

    "Default Domain" could be the same as my section starting "A further twist ..."

    "Primary and Secondary DNS" ... is the same as my section starting "The trouble I had, ..."

That being the case, then leaving Default Domain blank will probably be fine , as it only adds a "TLD" to the effective 'host name' of the server.

I don't think the Primary and Secondary DNS are going to help, (unless you set up a local DNS server, but I don't think you need to), as they are normally intended to access external DNS servers.

-------------------

The problem is the laptop can't pig the PI and the PI can't ping the laptop.

DHCP settings shouldn't directly affect the ability of two computers to ping each other. Two machines with IPs in the same subnet ... e.g. 192.168.0.100 an 192.168.0.11 should be able to communicate with each other if the subnet is set to 192.168.0.x, regardless of how they were set those addresses.

However, whilst computers often do support ping, sometimes they are set up to ignore ping requests. So before drawing any conclusions, I would start by testing the ping route in a simplified 'network' configuration, with both machines directly networked to the same router. Also try pinging the router (192.168.0.1 in most cases) from each machine.

----------------------

Best wishes, Dave


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi @zander,

  And yet more notes ... I hadn't noticed the trail went to another page ...

I suspect the mac to ip binding only works on ethernet cable type connections

Don't think so .. they should work for both WiFi and wired connections ... but don't forget the wired and WiFi will have different MACs ... so each MAC can have its own personal IP address.

-----------------------

Should I edit the wpa-supplicant.conf file and completely delete the 5G entry?

Good to hear that you have got some form of communication, but, sorry, I am getting lost with your configuration .. and I haven't come across a wpa-supplicant.conf file.

------------------

I am inclined to suggest you simplify everything as much as possible, just assign fixed IP addresses using the router DHCP to all of the important 'players', plus assign a hostname to the ESP32, and see if you can link it up with just one router, andthe ESP32 close enough to it.

Hopefully, this will eliminate the need for any other .conf files -- or maybe I have forgotten something?

Maybe do it stages, because I don't understand why you suddenly got a 5G connection ... and obviously you need 2.4G connection for the ESP32, so also get 2.4G connections working.

If it works at short range, then extend to the required locations, adding a repeater function if necessary.

------------

Good luck. Best wishes, Dave

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee Sorry Dave, I think I confused you somewhere along the way. Forget about the esp32, it's not a part of the problem.

Let me start at the end. My Raspberry Pi can no longer see my router. I even loaded a fresh copy of Raspbian. That means I somehow broke the router. Tomorrow or when I have time I will attempt to reset the router.

My setup is somewhat unusual. My little router is more like a modem as it connects to the internet by a wifi signal. That router ois attached to another router and that is attached to a modem with a cable WAN input. This is how the campgrounds gives us free (really stolen) WiFi.

The little router is NOT in range extender mode, it's in share hotspot mode. It has a USB GSM phone connection I am not using at this time. My internet comes into this box via wifi.

I assigned addresses from 2 to 99 as dynamic, then using the standard dhcpd.conf file assigned a static ip for the Pi.

Long story short, my Pi can NOT see the router anymore and I even tried a fresh install. Somewhere probably in the router something is badly messed up.

I just got off a 90 min phone call with my daughter and it's time to settle down so I will look at this more in a couple days as I have appointments part of the day tomorrow and the next day.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee I can't find a way to delete the 5G but I did untick the broadcast SSID so it is effectively gone. At this moment nothing works, I can't get the Pi to attach to any WiFi. Other responses have more details.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

UPDATE:

This morning the PI4 finally got connected to the local net. It did take it's sweet time, at first nothing then when I hovered the WiFi icon I noticed it said something about my SSID but wasn't showing the normal activity icon. After a short delay all returned to normal. It appears that establishing a static ip (as set up in the dhcpcd.conf file) actually takes longer than a dynamic. I tested everything with simple pings, and now my RaspberryPi can be accessed as PI41.local (I would love to get that domain thing working, but one step at a time) I then fired up the app and the mqtt messages started showing up on the Pi !!!!

Finally back to square 1.

After getting my first coffee, I will comment out the static settings and add MAC to IP settings in the router. I do like having the static addresses centralized.

Much thanks to @davee for his patience, this old dog can learn a new trick or two once in a while, but it does take longer than it used to.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi Ron @zander,

   --- I was writing this note ... when my email pinged you have sent a new note, saying the R-Pi is more cooperative today ... I'll continue with this note, but apologies if it looks a little 'dated' by your most recent experience. There might be something useful ... meanwhile, good to see you are getting some progress.

 

   Fine, No problem ... I am confused all the time ... with or without the aid of phantom ESP32s. 😀 

I understand how you are connecting to the Internet, but I am less clear about what follows.

The chain seems to be:

Campsite Wifi <--> Small Router <--> Main Router

However, it is less clear which of the two routers you are trying to connect your client/server devices, such as R-Pi, Laptop, etc. to .. or maybe to both routers, albeit each device only connects to one router at a time?

I am guessing that you are effectively using the small router as a through link, so it is only directly linking to the campsite and the main router ... but I am not sure.

Trying to use both routers to link directly to your other devices could be very messy, and I would be inclined to not do it, if possible.

------------

It is also not clear how much of your overall local network of routers, client/server devices and so on, actually work as you would hope. I understand the R-Pi is having a bad time, but it is less clear if it is limited to the R-Pi specifically, or if other devices are also having issues.

----------

If the chain is as above, all of your client/server devices are linking to the main router, and the chain seems to be working, so that the issues are mainly with the router to client/server devices .....   then my suggestion is that you take a deep breath ... and decide to reconfigure the main router from scratch.

I realise you might only need to change one or two things, but I know from bitter experience how easy it is to have something wrong, and how hard it is to fix it. Not only can it be a pain if it doesn't play nicely, but it might also have left a 'hole' for some low life to make your life even more miserable.

To do this, using all the stuff from previous notes in this thread, I would:

  1. Connect a 'reliable' PC to the router using an Ethernet cable ... this will be used to set up the router config.
  2. Log in into the router on this PC.
  3. Make a back up copy of the router configuration on the PC, naming the file appropriately, so you can return to the present  config if all else fails...
  4. Make sure the router has the latest firmware.
  5. Do a factory reset on you router
  6. Do a minimal enable of wired and WiFi, more or less just setting SSID and password, so your other devices can log in, using the default DHCP with auto IP allocation.
    • It might be helpful to split the address space into 'auto-allocate' and 'fixed-IP' allocate zones, so that all devices initially go in the 'auto' space, leaving the 'fixed' part empty for you to allocate into later. (This usually just means setting limits for the auto-allocate addresses.)
  7. Check that your devices, particularly the R-Pi and any other ones previously having problems, can communicate in all the usual ways.
  8. Take another back up copy of the router configuration, naming it appropriately, to save time if you want to 'start again' later.
  9. Now start to 'refine' the DHCP, allocating the static IPs. Personally I like all of them to be static, as it helps diagnose what is happening, but the important ones are those with a 'server-like' function, such as your MQTT.
    • By the way, you may find your phones (and possibly tablets) do not have a fixed MAC address ... I haven't looked into it properly, but I have the impression they trying to improve your 'privacy' by making it harder to track where your phone is. This functionality may switchable in the phone's setup. But this might be a reason for it to be in the auto-IP allocation set!
  10. Once again, another router config backup is an excellent idea.
  11. Now, hopefully you have a 'solid' network, and can begin to do all the clever stuff that I currently do not understand, like setting up the MQTT server ...

Best wishes and good luck, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee I didn't read past the beginning because I have successfully confused you. The big router has not been brought out to play, that was just a threat to scare tiy router into behaving.

Your diagram is otherwise correct, campsite wifi<--->small router (called a WISP I think, WiFi ISP)

This morning with the PI configured via the DHCP daemon on the PI everything worked!

For the last hour I have been trying to get the PI to recognize the MAC to IP mapping in the router but that is not working.

I just confirmed that I do indeed have a dhcp daemon running on my PI.

I just found a stackexchange article that tells me the IP I want to assign must be IN the dynamic range. IOW, 192.168.0.2 to 192.168.0.99 as dynamic that I have now is wrong if I want the PI to be 192.168.0.100, the dynamic range has to be wider, in fact why would I have less than 2-254?

Trying that now, stay tuned.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee I forgot the article link https://raspberrypi.stackexchange.com/questions/137443/dhcpcd-conf-inform-vs-static-ip-vs-request-how-should-you-really-setup-a-static

BTW, I powered down the PI, pulled the power cable on the router and just now powered the PI back up. Still a dynamic IP.

I see what is a hnew feature to me, if I click the WiFi icon I can enter an IP plus router address, dns etc. I checked and it does update the dhcpcd.conf file.

I will leave the router with it's binding in the hope that prevents the router dhcp ever allocating that address to anybody else but as of now, it looks like the router does not work and the interface in Raspbian OS is simple so I will leave it at that.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi Ron @zander,

  You have my sympathies in trying to get the MAC to IP mapping to work, but I am pretty sure the 'advice' from Stackexchange this time is wrong, or at best misleading!

I have seen nothing to suggest that when the router sends DHCP settings including an IP address, that the client knows (or cares) how the router decided on that IP address, including whether it was in the 'auto-IP' or the 'fixed-IP' range of addresses.

If you have (say)  IP Network address is 192.168.0.0

                           Subnet mask is         255.255.255.0

Then all addresses from 192.168.0.0 to 192.168.0.255 are the same subnet, so that all devices with addresses in that range can directly talk. (192.168.0.0 and 192.168.0.255 are 'special' and never assigned to 'real devices'.) 

How devices get allocated in the range 192.168.0.1 to 192.168.254 has no bearing on how they communicate.

In my experience of Windows and Linux (mainly, but not only Ubuntu), I have never found a device which did not obey the DHCP server commands from the router.

Occasionally, I have had problems finding the 'right' MAC address ... and too many times, I have had trouble typing the MAC address correctly ... both of which obviously cause a failure!

As far as possible, I usually try to get the router to discover the MAC address in the 'auto-IP' mode, and then edit that information to create a 'fixed-IP' entry. This is sometimes copy and paste, but my present router offers a kind of drop down box, which is easier.

Best wishes,

Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee The underlying problem I believe is that the PI itself is a dhcp server. I need to turn it off before the router can work.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi Ron @zander,

  Once again our emails have crossed in the Ether.

  Obviously, if you have a workaround, then you can proceed, but I suspect there is  'simple' reason ... though not necessarily a simple way of discovering it.

i would try allocating an IP address to something else, albeit not a phone/table, to see if it works.

I have been using it for about 20 years, and almost all problems have been bad typing, with a few mystery cases of getting a different MAC address!

Good luck, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7099
Topic starter  

@davee The PI has a dhcp daemon running, that is the normal unix way of setting up static addresses. I even have a GUI element on the screen to change from dynamic to static without editing the dhcpcd.conf file like is normally done. What I need to do is turn off the dhcp daemon in oder for the router settings to work for this PI.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Page 2 / 4