Can't connect through SSH from another PC on the same network Topic is solved

Having issues with your DietPi installation, or, found a bug? Post it here.
riccardo
Posts: 6
Joined: Sat Jan 19, 2019 8:47 pm

Re: Can't connect through SSH from another PC on the same network

Post by riccardo »

Just to be clear, I was not using a plug-in interface, just the internal one.
Not sure if it's useful info, but I thought it was better to clarify.
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Can't connect through SSH from another PC on the same network

Post by MichaIng »

Thanks for the info.

I am not sure what caused the wrong /DietPi/dietpi/.network entry or at least WiFi monitor scraping the wrong network interface, but in every case v6.20 will prevent this, instead will throw an error and exit, if no correct interface was found.
tped
Posts: 7
Joined: Fri Jul 06, 2018 5:27 pm

Re: Can't connect through SSH from another PC on the same network

Post by tped »

RPI 3, inbuilt wifi (wlan0), DietPi v16.7

I just noticed all the wifi-monitor journal chatter too (repeated detected connection loss, down/up with incorrect interface). I disabled wifi-monitor service for now ...

I saw the following during startup - Could dietpi-wifi-monitor.sh have something to do with getting wrong interface?

Code: Select all

Jan 21 06:45:15 HomePiV3 bash[424]: /var/lib/dietpi/services/dietpi-wifi-monitor.sh: line 5: /DietPi/dietpi/func/dietpi-globals: No 
such file or directory
Jan 21 06:45:15 HomePiV3 bash[424]: /var/lib/dietpi/services/dietpi-wifi-monitor.sh: line 7: G_CHECK_ROOT_USER: command not found
Jan 21 06:45:15 HomePiV3 bash[424]: /var/lib/dietpi/services/dietpi-wifi-monitor.sh: line 8: G_CHECK_ROOTFS_RW: command not found
Jan 21 06:45:15 HomePiV3 bash[424]: /var/lib/dietpi/services/dietpi-wifi-monitor.sh: line 9: G_INIT: command not found
Jan 21 06:45:15 HomePiV3 bash[424]: sed: can't read /DietPi/dietpi/.network: No such file or directory
Jan 21 06:45:15 HomePiV3 bash[424]: Cannot find device "wlan"
Jan 21 06:45:15 HomePiV3 bash[424]: Checking connnection for: wlan via ping to
sed -n 2p /DietPi/dietpi/.network returns 0 (zero)

Repeated chatter looks like this

Code: Select all

Jan 21 06:46:41 HomePiV3 bash[424]: Cannot find device "wlan"
Jan 21 06:46:41 HomePiV3 bash[424]: Checking connnection for: wlan via ping to
Jan 21 06:46:41 HomePiV3 bash[424]: Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
Jan 21 06:46:41 HomePiV3 bash[424]:             [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
Jan 21 06:46:41 HomePiV3 bash[424]:             [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
Jan 21 06:46:41 HomePiV3 bash[424]:             [-w deadline] [-W timeout] [hop1 ...] destination
Jan 21 06:46:41 HomePiV3 bash[424]: Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
Jan 21 06:46:41 HomePiV3 bash[424]:              [-l preload] [-m mark] [-M pmtudisc_option]
Jan 21 06:46:41 HomePiV3 bash[424]:              [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
Jan 21 06:46:41 HomePiV3 bash[424]:              [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
Jan 21 06:46:41 HomePiV3 bash[424]:              [-W timeout] destination
Jan 21 06:46:41 HomePiV3 bash[424]: Detected connection loss: wlan. Reconnecting
Jan 21 06:46:41 HomePiV3 bash[424]: ifdown: unknown interface wlan
Jan 21 06:46:42 HomePiV3 bash[424]: ifup: unknown interface wlan
Jan 21 06:46:42 HomePiV3 bash[424]: Completed
Jan 21 06:46:44 HomePiV3 dhclient[809]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
Jan 21 06:46:48 HomePiV3 dhclient[809]: No DHCPOFFERS received.
Jan 21 06:46:48 HomePiV3 dhclient[809]: No working leases in persistent database - sleeping.
Jan 21 06:46:52 HomePiV3 dhclient[809]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3
Jan 21 06:46:52 HomePiV3 bash[424]: Cannot find device "wlan"
Jan 21 06:46:52 HomePiV3 bash[424]: Checking connnection for: wlan via ping to
Jan 21 06:46:52 HomePiV3 bash[424]: Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
Jan 21 06:46:52 HomePiV3 bash[424]:             [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
Jan 21 06:46:52 HomePiV3 bash[424]:             [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
Jan 21 06:46:52 HomePiV3 bash[424]:             [-w deadline] [-W timeout] [hop1 ...] destination
Jan 21 06:46:52 HomePiV3 bash[424]: Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
Jan 21 06:46:52 HomePiV3 bash[424]:              [-l preload] [-m mark] [-M pmtudisc_option]
Jan 21 06:46:52 HomePiV3 bash[424]:              [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
Jan 21 06:46:52 HomePiV3 bash[424]:              [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
Jan 21 06:46:52 HomePiV3 bash[424]:              [-W timeout] destination
Jan 21 06:46:52 HomePiV3 bash[424]: Detected connection loss: wlan. Reconnecting
Jan 21 06:46:52 HomePiV3 bash[424]: ifdown: unknown interface wlan
Jan 21 06:46:53 HomePiV3 bash[424]: ifup: unknown interface wlan
Jan 21 06:46:53 HomePiV3 bash[424]: Completed
Jan 21 06:46:55 HomePiV3 dhclient[809]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
Jan 21 06:46:59 HomePiV3 dhclient[809]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
Happy to dig deeper and provide more info as needed
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Can't connect through SSH from another PC on the same network

Post by MichaIng »

@tped
Thanks for the info.
/var/lib/dietpi/services/dietpi-wifi-monitor.sh: line 5: /DietPi/dietpi/func/dietpi-globals: No
such file or directory
Hmm that is strange, since file definitely exists, especially since sed -n 2p /DietPi/dietpi/.network returns the correct value, so the RAMdisk is inplace. Failing on that, the other failures are expected.

To verify:
  • You are on DietPi v6.19.7 right?
  • You did enable the the WiFi monitor via dietpi-config, right?
  • Does sudo /var/lib/dietpi/services/dietpi-wifi-monitor.sh throw the same errors?
    This will start the process in foreground, exit by pressing: <ctrl>+<c>
  • If the above works, check if manually starting the service works as well: systemctl start dietpi-wifi-monitor
  • Check systemctl status dietpi-wifi-monitor for any errors after Starting DietPi-WiFi-Mintor...
  • Run systemctl stop dietpi-wifi-monitor to stop is again.
  • If this works as well, retry via dietpi-config
Sorry for being a bid too much in detail here, by this is help any other, possibly less experienced user to follow ;).

If some failure/error still happens, please try the current dev versions of the service:
- systemd unit: https://github.com/Fourdee/DietPi/blob/ ... or.service
- script: https://github.com/Fourdee/DietPi/blob/ ... monitor.sh
tped
Posts: 7
Joined: Fri Jul 06, 2018 5:27 pm

Re: Can't connect through SSH from another PC on the same network

Post by tped »

Thanks for the detail - I 'll take all the help I can get!

It is Strange indeed ... and yes, the /DietPi/dietpi/.network file DOES exist
You are on DietPi v6.19.7 right?
You did enable the the WiFi monitor via dietpi-config, right?
Does sudo /var/lib/dietpi/services/dietpi-wifi-monitor.sh throw the same errors?
This will start the process in foreground, exit by pressing: <ctrl>+<c>
If the above works, check if manually starting the service works as well: systemctl start dietpi-wifi-monitor
Check systemctl status dietpi-wifi-monitor for any errors after Starting DietPi-WiFi-Mintor...
Run systemctl stop dietpi-wifi-monitor to stop is again.
If this works as well, retry via dietpi-config
My todo list:
  • DietPi version is 16.19.7 (sorry type-o'ed that before)
  • I DID NOT (intentionally) enable Wifi Monitor via DietPi-Config! (Where is that option?)
    My WiFi options: Autoreconnect [off], Mode [DHCP], Country [US]
  • sudo /var/lib/dietpi/services/dietpi-wifi-monitor.sh DOES NOT throw same error - it seems to have correct connection (wlan0)

    Code: Select all

    root@HomePiV3:~# sudo /var/lib/dietpi/services/dietpi-wifi-monitor.sh
    [  OK  ] DietPi-WiFi-Monitor | Root access verified.
    [  OK  ] DietPi-WiFi-Monitor | RootFS R/W access verified.
    
    Checking connection for: wlan0 via ping to <my gateway address>
  • systemctl start dietpi-wifi-monitor seems to start it fine ... output looks same as running it in foreground, no errors
  • Not sure how to 'retry via dietpi-config' BUT I started the service via "dietpi-services start dietpi-wifi-monitor" and it seems to be working fine! I checked the status using systemctl status dietpi-wifi-monitor
One more quick test ...
I rebooted and checked ... looks like it is not working

Code: Select all

root@HomePiV3:~# systemctl status dietpi-wifi-monitor.service 
● dietpi-wifi-monitor.service - Monitors loss of WiFi connection and automatically reconnects
   Loaded: loaded (/etc/systemd/system/dietpi-wifi-monitor.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-01-21 15:42:38 CST; 2min 35s ago
 Main PID: 420 (dietpi-wifi-mon)
   CGroup: /system.slice/dietpi-wifi-monitor.service
           ├─ 420 /bin/bash /var/lib/dietpi/services/dietpi-wifi-monitor.sh
           └─1805 sleep 10

Jan 21 15:45:11 HomePiV3 bash[420]:             [-w deadline] [-W timeout] [hop1 ...] destination
Jan 21 15:45:11 HomePiV3 bash[420]: Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
Jan 21 15:45:11 HomePiV3 bash[420]:              [-l preload] [-m mark] [-M pmtudisc_option]
Jan 21 15:45:11 HomePiV3 bash[420]:              [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
Jan 21 15:45:11 HomePiV3 bash[420]:              [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
Jan 21 15:45:11 HomePiV3 bash[420]:              [-W timeout] destination
Jan 21 15:45:11 HomePiV3 bash[420]: Detected connection loss: wlan. Reconnecting
Jan 21 15:45:11 HomePiV3 bash[420]: ifdown: unknown interface wlan
Jan 21 15:45:12 HomePiV3 bash[420]: ifup: unknown interface wlan
Jan 21 15:45:12 HomePiV3 bash[420]: Completed
Manually ran sudo /var/lib/dietpi/services/dietpi-wifi-monitor.sh ... Ran fine, pinging my gateway again!

Stopped and started the service using dietpi-services and it came up fine

Strange indeed. I wonder where/when/how does /DietPi/dietpi/.network get populated? Especially @ bootime. Could the service start before the file gets built?

I'll check dev versions, but prob not until tomorrow. Feel free to shoot me more todo's if you need more info

Hope it helps.
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Can't connect through SSH from another PC on the same network

Post by MichaIng »

Ah okay, so it works fine now.

/DietPi/dietpi/.network is boot persistent, so as long as nothing changes about the WiFi adapter and gateway it connects to, this should be correct.
It is also generated on boot and whenever on touches network settings via dietpi-config.

And as above updates, the monitor service will now also update the file. /DietPi/dietpi/func/obtain_network_details is the responsible script that checks attached network devices, their connection state, IP, gateway and such, so scripts know which adapter to handle in which way.
tped
Posts: 7
Joined: Fri Jul 06, 2018 5:27 pm

Re: Can't connect through SSH from another PC on the same network

Post by tped »

It only works if I stop/start the service manually after each reboot

I disabled the service via dietpi-services for now ... things are quiet

Where is the wifi-monitor option in dietpi-config?
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Can't connect through SSH from another PC on the same network

Post by MichaIng »

Ah sorry, I was not reading carefully. Will run some other tests here. Perhaps the boot script, rewriting /DietPi/dietpi/.network and the monitor reading it somehow interfere, so we need to start the script at a later boot state be avoid this.

Usually you would enable/disable it via: dietpi-config > Network Options (Adapters) > WiFi > WiFi monitor
Not sure about the last two menu entry names, my WiFi test system currently not up, but by should be something like this by meaning ;).

I opened an issue on GitHub to collect some commits and info. I think that should solve it, but will run some tests with different boot orders to exclude other interferences: https://github.com/Fourdee/DietPi/issues/2434

@tped
If you find time, would be great if you could test them as well, since every system/network adapter behaves a bid different:

Code: Select all

wget https://raw.githubusercontent.com/Fourdee/DietPi/dev/rootfs/etc/systemd/system/dietpi-wifi-monitor.service -O /etc/systemd/system/dietpi-wifi-monitor.service
wget https://raw.githubusercontent.com/Fourdee/DietPi/dev/rootfs/var/lib/dietpi/services/dietpi-wifi-monitor.sh -O /var/lib/dietpi/services/dietpi-wifi-monitor.sh
chmod +x /var/lib/dietpi/services/dietpi-wifi-monitor.sh
systemctl daemon-reload
tped
Posts: 7
Joined: Fri Jul 06, 2018 5:27 pm

Re: Can't connect through SSH from another PC on the same network

Post by tped »

Probably worth mentioning - I don't see the Wifi-monitor option in dietpi-config. I double/triple checked dietpi version, even did a dietpi-update to be safe, but no updates required - I am indeed on v6.19.7. dietpi-config wifi options look a little like this:

●─ Basic Options ───────────────────────●
Scan : Scan and configure SSID
Auto Reconnect : [On]
●─ DHCP/STATIC IP ──────────────────────●
Change Mode : [DHCP]
●─ Additional Options ──────────────────●
Country : [US]
●─ Toggle State ────────────────────────●
Disable : Disable WiFi adapter
●─ Apply ───────────────────────────────●
Apply : Save all changes and restart networking
---------------

I also downloaded and swapped in the new dietpi-wifi-service per yesterday's instructions

it's REALLY quiet now - here's chatter since last reboot

Code: Select all

root@HomePiV3:~# systemctl status dietpi-wifi-monitor.service 
● dietpi-wifi-monitor.service - DietPi-WiFi-Monitor
   Loaded: loaded (/etc/systemd/system/dietpi-wifi-monitor.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-01-23 06:20:34 CST; 34min ago
  Process: 1022 ExecStartPre=/bin/bash -c [[ -e /sys/class/net/wlan$(sed -n 2p /DietPi/dietpi/.network) ]] (code=exited, status=0/SU
CCESS)
  Process: 905 ExecStartPre=/DietPi/dietpi/func/obtain_network_details (code=exited, status=0/SUCCESS)
 Main PID: 1027 (dietpi-wifi-mon)
   CGroup: /system.slice/dietpi-wifi-monitor.service
           ├─1027 /bin/bash /var/lib/dietpi/services/dietpi-wifi-monitor.sh
           └─5675 sleep 10

Jan 23 06:20:34 HomePiV3 systemd[1]: Starting DietPi-WiFi-Monitor...
Jan 23 06:20:34 HomePiV3 systemd[1]: Started DietPi-WiFi-Monitor.
Jan 23 06:20:34 HomePiV3 dietpi-wifi-monitor.sh[1027]: [56B blob data]
Jan 23 06:20:34 HomePiV3 dietpi-wifi-monitor.sh[1027]: [62B blob data]
Jan 23 06:20:53 HomePiV3 dietpi-wifi-monitor.sh[1027]: Checking connnection for: wlan0 via ping to default gateway every 10 seconds
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Can't connect through SSH from another PC on the same network

Post by MichaIng »

@tped
Its the Auto Reconnect : [On] option, so jep enabled and running.

So seems now it is really running (and starting on reboot) as intended 8). Jep it should be quiet until a connection loss is detected and reconnection attempted, so it does not spam journalctl/syslog every 10 seconds, if everything is actually fine.

If your device (or WiFi AP) is mobile, you could move one out of range, wait there for at least 10 seconds and move it in range again. The service should then automatically reconnect after another maximum of 10 seconds (tick rate).

More verbose output is done when passing G_DEBUG=1 as variable. Should be not required, besides for testing reasons. If you want to pass that variable to the systemd unit to see the script doing it's connection check every 10 seconds:
Put Environment=G_DEBUG=1 to into it's [Service] section, systemctl daemon-reload to reload the unit and systemctl restart dietpi-wifi-monitor.

Btw: Many thanks for all the testing and feedback :D !
Post Reply