When I switch my laptop from LAN to WLAN, DNS still replies old IP

Hi,
I have a PC and a laptop, and I need to access the laptop from the PC via ssh and VNC. Most times, the laptop is connected via LAN. But sometimes, I move it to a place where I don’t have LAN.
When I do that, the laptop’s network manager switches the connection, and it still can access the internet (and the PC), but the PC can’t access the laptop anymore. I found out that nsloopkup laptop still replies the IP from the LAN connection.

Is there a way to update the router’s DNS when the laptop requests a new DHCP lease using the same hostname ?
Or better … Is there some setting to have this update done automaticallly ?

I can use ssh and VNC using the IP instead of the hostname, but all my scripts and the VNC settings (remmina) are set up to the hostname and I would like to avoid having to change all of them, as the IP also changes when I switch.

It shouldn’t matter if it’s WLAN or LAN since it’s the same bridge and same DHCP server serving you DNS. And if you connect in a diffrent way it shouldn’t matter since IP stays binded to the MAC address of the device for longer time. 12h by default if I am not mistaken.

What you could do is to add static entry in /etc/hosts (linux) and $HOSTS_FILE (windows - I don’t know where is it):
laptop 192.168.0.152 like that for example.

or add static IP for your laptop using LuCI in DNS settings.

So to conclude it’s normal that your IP doesn’t change that often. It depends on the DHCP lease time.

The problem is that the IP does change when I change the connection, while the DNS reply stays the same.

Yes, the DHCP lease expires after 12h, but even then DNS always replies the same IP. The only way so far I could successfully make the router reply the current IP was to reboot it. And then I’m bound to this connection until I reboot it again.

When you switch from wire to wifi the IP
has to change because you use different network card of you laptop with different MAC address. From router perspective it is different device. And it cannot have two different MAC/IP s binded to the same name at the same time, until the first expires.
You can try:

  • give the same MAC to both LAN and WiFi cards
  • or, assign the same static IP to both MAC in your DHCP
  • In DNS it is possible to have multiple IPv4 addresses on a single name and it’s perfectly supported in kresd… but it’s not what you want anyway :slight_smile: I’ve never seen an application that uses this to skip over addresses that don’t work.
  • I can imagine newer bindings winning over the older ones, at least theoretically. Maybe it wouldn’t be too hard to do that on the level of the script that sits between DHCP and DNS. (but I’m not working on that)

@xsys

When you switch from wire to wifi the IP has to change because you use different network card of you laptop with different MAC address.

Yes, but that’s not the problem. The problm is that DNS is too stubborn to give me the new address when it changes.

give the same MAC to both LAN and WiFi cards

Oh, I’ve never tried something like that. I hope it’s not useless because they sit on different media (cable vs. waves).

or, assign the same static IP to both MAC in your DHCP

I did not know that I can usa double entries there.

Well, your suggestions could be a workaround. But a real solution would be what vcunat wrote … newer bindings should win over (or completely replace) older ones.

@vcunat

I can imagine newer bindings winning over the older ones,

That would be sufficient. However, it currently does not work this way. Unfortunately, I’m not able to adapt the script.