Static dhcp lease per interface - networking

Can I force any device plugged into a particular Ethernet port on a router or managed switch to receive a fixed IP address, without knowing its MAC or anything else? I'm thinking there's a way to do this in dd-wrt, but it doesn't need to be that platform. Would need to be able to run it on a managed switch, or at least something with more than four ports. I'd also need to be able to swap them out quickly, so not wait for lease expiry. Don't need a step-by-step solution, just a bearing would help.

Short answer: no.
Longer answer: Trying to get a certain (reserved) IP address leased to a device on a specific switch port would need to overcome several problems:
The DHCP server doesn't know the switch port of the DHCP client asking for an offer.
The DHCP server doesn't know when a device has disconnected and its lease is potentially free again.
The closest I can imagine is a separate VLAN per switch port with a single IP address in the VLAN scope and a very short lease time. The DHCP server would also need to be directly connected with each VLAN, alternatively you could use a DHCP agent or relaying on the switch.

Related

How do modems connect with ISP?

AFAIK when i turn on my modem, it says: "Hi ISP, i need an IP".
Then, my ISP give it an IP.
How does my ISP identify my modem? by last IP, key, or what?
After i have an IP, i can navigate, but after some hours my modem changes its IP.
2) How is that change done?
I mean, my ISP says: "Hi user modem, there is your new IP"
It gets even funnier if when i turn on my modem, some other modem has the last IP my modem had.
There is a collision. So, my ISP would give my modem another IP, wont it?
I know im talking about technical stuff, but i would like you to explain me in your own words in order not to make it cumbersome.
If technical references arise, maybe just name the concept or leave a link. It would be enough for me.
Thanks you all!
By posting under the tag „dhcp“, you are obviously already assuming that the DHCP protocol is the answer to your questions:
The DHCP Protocol allows the DHCP Server (your ISP) to identify the DHCP client (your modem) by a multitude of information. The most important one is usually the MAC address of your modem. The last IP is also transmitted from client to server along with proprietary information such as the client identifier and others.
The server supplies the IP address along with a lease time. The client will renew the IP address with the DHCP server when the lease time is about to expire. The server decides in the renewal process triggered by the client if the same IP is ok to use further or not.
Restart is not much different from renewal. The DHCP protocol is for that purpose equipped with a broadcast feature so the collision does not really happen, because the client (modem) will ask for an IP address before it uses the old IP.
It is possible that modem and ISP do not use DHCP but the mechanism is probably similar. DHCP is specified in RFC 2131.

Will DHCP server give me always same IP?

I have question on DHCP server in home router. I have founded, that I have same IP address in my notebook for some time. I don't know, how long it last, but it is probably few weeks at least. Will DHCP server ever change my local IP if i will still connecting to that Wi-Fi?
I am asking, because I am working on home automation system and I don't know if i had to keep care about checking if my devices has same IP...Because there will be server, which will remember IP of its clients (lets say ESP8266 modules). Must I periodically check IP address (in my modules) and send new IP to server (in case of change)? Or DHCP server will not change IP address of my modules, connected to that DHCP server? And what about situation when ESP8266 module will disconnect (lets say it will be off for few days) - is it common to get different or same IP from DHCP after connection again?
Thanks!
Simple solution would be reserving IP address for your ESP8266 modules in your DHCP server that they always receive the same IPs.
With regards to your questions:
My routers DHCP server saves clients and keep information about them unless it is deleted explicitly or number of saved clients gets larger than number of addresses available. It serves always the same IP to saved clients. Obviously it depends on the router and might be different in your case.
I'd not check for IPs manually, I'd rather reserve the IPs for the modules as said above.
If your DHCP server stores client information it will give the same IPs to your modules upon reconnect. Otherwise not it won't be necessary the case.
If you use or consider using MQTT server (my preferred way :) ) for your home automation (it has integration in many systems like e.g. Home Assistant) you won't need to care about IP addresses of your modules at all you'd only need to fix IP of the MQTT server.
Another option can be addressing your modules (or/and server) using host name instead of IPs. If you develop n Arduino this GitHub thread might be helpful.

Local Area Network Configuration Question

Comcast installed a Juniper Universal Access Router ACX1100, I plugged our switch to the port that the technician told us that is in/out port. But nothing happened, after reading and asking I was told that I need a managed switch to be configured with the gateway IP and that IP is a /29. That's where I got lost. According to him there are 6 usable IP's.
example:
Gateway: 192.168.120.161/29
Usable Range: 192.168.120.162 - 192.168.120.167
One of my multiple questions is what hardware do I need to be able to connect my PC's?, I configured a managed switch, but when I connect my laptop to it I get Unidentified Network and No Internet Connection.
I have been reading and I think I need a VPN with DHCP server integrated.
If some one can help me I'll appreciate it.
/29 is the subnet mask, it can also be expressed as 255.255.255.248. Basically it defines which part of the IP is the network ID and which part of IP is the host ID.
I think in order to accurate assess your situation, we need to know exactly what kind of configuration you set on the managed switch you purchased, also which managed switch did you purchase?
Also currently on your laptop's NIC, what IP is assigned on there?
Either on your old unmanaged switch or on the managed switch, you can try assigning one of the addresses from the /29 block that the technician told you about statically. And the default-gateway with the addresses you posted in your question.

Multiple Mosquitto brokers to exchange data between devices

I have 3 devices each of them have Mosquitto broker running on them. Each of this device has subscriber and publisher.
I am using IP of each device to open port at 8883 and exchange messages --> subscribe/publish their messages. If the case happens to be that devices use dynamic IP., How can I publish new IP-PORT address to its clients that are already connected? How to tackle this problem. Is my approach correct? Is there any other way I can create my own private IP-PORT address to the broker?
Your broker needs to be reachable at a known location, be that fixed IP address or a DNS entry that points to it's current IP address.
Any clients connected at the time the IP address changes will be disconnected and will need to reconnect.
You've not said if these are all on the same LAN or spread across the internet, but either way you need some sort of dynamic DNS solution.
If the devices are all on the same LAN then you can use Avahi/mDNS/Bonjour to discover the current address of the device in the .local domain. Each broker will need to have a unique name.
If you are in a none lan environment then you will need to use a proper Dynamic DNS solution and have each broker have a unique fully qualified DNS name that the host machine can update when ever it's IP address changes.
Both of these solutions are more network admin solutions than programming questions so I suggest you ask on SuperUser if you have follow up questions.
There is a 3rd option, which is to have a 4th broker on a fixed IP address that acts as a central bridge for all the other brokers.

Automatically detect a new computer connected to the network

Is there an elegant way to make a program detect a new computer that is connected to the network?
I would like my program to "auto-sense" a new computer being connected on the network (they're on the same network). Like a USB device being connected to the computer.
What I'm doing now is to save a list of all computers in the network from time to time. Another approach is to PING all available IPs on the subnet.
Are there any other elegant approaches?
Thanks!
Listening for ARP requests is the canonical way to do this. Independent of DHCP or not, any connected computer that wishes to communicate with the outside world will have to make an ARP request for the address of the default router. This request will go out as a broadcast, and contain the source interface's MAC and IP adresses.
If the other computer uses DHCP, it will make an ARP request for it's own address as part of duplicate address detection, which is also a broadcast you can snoop on.
(This works more or less the same way for IPv6, except you need to look for neighbor discovery or router soliciation packets instead.)
Like the answer alluded to, if you have a switch to which you can telnet or use SNMP on, you can extract the MAC table. That will give you a list of MAC adresses on each port in the switch. If you want the IP addresses however, you still need to listen for ARP:s.
On the other hand, if you have access to the default gateway on the network, you can also look at the ARP table there. That will give you MAC and IP addresses for anyone that has recently (for different values of recently...) communicated with it.
If you have a managed switch of some kind, you could probably connect to that, that would be a fairly elegant method.
If you're on a domain, you can can get a list of all the machines joined to the domain from the domain controller.
Failing that, all I can think of is either a challenge/response thing (e.g. pinging them) or by detecting traffic sent from them (see this question maybe as a starting point?), neither of which strike me as an elegant approach.

Resources