WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: wlan0 is up, but I can't reach host, unless first contact is made from wlan0  (Read 3415 times)

Offline Twist

  • Newbie
  • *
  • Posts: 41
disclaimer: issue might not be picore related ... please enlighten me

I'm running picore12 on a Pi0W, minimal extensions to bring up wifi and ssh. All good after boot.
When I leave this Pi0W alone for a while (e.g. overnight) - doing nothing basically - I can no longer connect via ssh. It times out with host unreachable. Looking at my router's admin page (which serves as the dhcpd on my lan), the Pi0W is no longer registered with its IP address.
Next I connect a serial console cable to see what's going on. Pi0W is up and running, happily serving me a login. A look at ifconfig and 'ps aux' shows me wlan0 is up, has an ip registered, and sshd is listening. Still not able to connect via ssh though. And still not visible on router's dhcp status page.
From the serial login I send a couple of pings to my router, which is succesful. And now the dhcpd status page shows the Pi0W again. But still not able to connect via ssh.
Then I send a couple of pings to the laptop trying to ssh in. Only then can said laptop ssh into the Pi0W.

It's as if the total lack of network activity on the wlan0 interface causes it to drop out of the routing table in my lan. Easy hack might be to script a ping package to the gateway every now and then. But surely there must be a more apt solution.

FWIW: fibre (internet) <-> router(also dhcpd) <-> wirelessAP <-> [wlan clients]


Offline Twist

  • Newbie
  • *
  • Posts: 41
Sorry, confused with old setup.
FWIW: fibre (internet) <-> router(also dhcpd) <-> wirelessAP <-> [wlan clients]
FWIW: fibre (internet) <-> router(also dhcpd and wirelessAP) <-> [wlan clients]

And, from the serial console on the RPi0W sending a ping to my router (not the laptop) actually unblocks the situation. I.e. adds the RPi0W in the APR table on the router.
« Last Edit: February 19, 2021, 04:40:52 AM by Twist »

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 715
You could try to setup the PI for static ip. Something could be wrong with the dhcp.
What lease time do you have with the dhcp server(router)?
Some ip traffic should be present. Like: Every 1/2 lease time of the dhcp, the client need to re-request the ip-address from the server.


Offline Twist

  • Newbie
  • *
  • Posts: 41
patrikg, static or dhcp shouldn't matter. Besides it gets the same address every time form the dhcpmserver. Plus I cannot afford to go static ip because of intended use case.
It is the lack of an ARP entry (on the router) that prevents my packets from arriving at the Pi. I now let the Pi send a ping to the router every 10 seconds, and that seems to do the job for now.
This is a router/ap with custom firmware from my isp. Suffice to say I do not like it  :-X (i.e. it is a piece of sh*t) On the list to replace with something decent, but hey...

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11641
HI Twist
What does this command return:
Code: [Select]
sudo sysctl -A | grep keepalive

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11641
HI Twist
And also these:
Code: [Select]
route
The contents of /etc/resolv.conf

Offline Twist

  • Newbie
  • *
  • Posts: 41
Hi Rich, the forum is throwing 'internal server errors' at me, but below is the output to those

Code: [Select]
net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_time = 7200

Code: [Select]
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 wlan0
127.0.0.1       0.0.0.0         255.255.255.255 UH    0      0        0 lo
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0

Code: [Select]
search home
nameserver 192.168.2.199



Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11641
HI Twist
What is  192.168.2.199 ??  I would expect the nameserver to point to the router (gateway) 192.168.2.1 or an external
address.

On the off chance your router drops connections due to a short timeout, you can try shortening the tcp_keepalive_time:
Code: [Select]
sudo sysctl -w net.ipv4.tcp_keepalive_time=600

Offline Twist

  • Newbie
  • *
  • Posts: 41
I'm running a pihole adblocker on .199 so that's as expected.
I'll give the reduced keepalive time a go and see if that helps. Will report back.
Thanks!

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11641
HI Twist
... And still not visible on router's dhcp status page. ...
When this happens, is the  pihole  still listed on the status page?

Offline Twist

  • Newbie
  • *
  • Posts: 41
When this happens, is the  pihole  still listed on the status page?
Yes all other devices on my lan are still listed.

The reduced keepalive seems to fix the issue. However I do notice a lag in response when initiating a new ssh sension, or continuing in an existing one. Pi (no, the network really) is unresponsive for a couple of seconds. This does not happen when I send a ping packet every 10 seconds.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11641
HI Twist
Keep alive  is basically just a mechanism used to verify and keep a connection open. All it does is send empty packets
and look for empty replies.

net.ipv4.tcp_keepalive_time:
The system will start to send  keep alive  packets after this many seconds of inactivity.

net.ipv4.tcp_keepalive_intvl:
After  net.ipv4.tcp_keepalive_time  times out, the number of seconds to wait between packets.

net.ipv4.tcp_keepalive_probes:
The connection gets closed after this number of sequential unanswered packets.

... This does not happen when I send a ping packet every 10 seconds.
You should get the same affect by doing this:
Code: [Select]
sudo sysctl -w net.ipv4.tcp_keepalive_intvl=10

Offline Twist

  • Newbie
  • *
  • Posts: 41
Yes, indeed your solution is more elegant running a ping process. thanks for your suggestion.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11641
HI Twist
Those settings will be lost when you reboot, so you may want to add those commands to your bootlocal.sh file.