Why can't Ubuntu access my Raspberry Pi across LAN?
Solution 1:
So until you had ufw
enabled with default settings on your Ubuntu machine the connection always reported Connection refused
. After you disabled the ufw
on you client the connection is established but the password is always rejected?
I would guess in that case your problem is that the 192.168.2.128
ip is routed back to your client Ubuntu machine, and actually you are connecting to the ssh
server running on your Ubuntu machine. This would explain:
Why you are able to connect from the internet.
Why your connection was rejected when the firewall was on on your Ubuntu client.
Why the connection is no more rejected with the client firewall turned off.
Why now the connection is established, but the authentication fail.
To troubleshoot this case:
Check the server's host key with
ssh -v [email protected]
both for a local and for an internet connection. Does it report the same key?Or while you are connecting from local, and you are at the prompt to type your password, from another terminal:
sudo netstat -tupan
and see if a connection is established to thesshd
on your Ubuntu.
Although this case would explain everything, but it is so weird that I have doubts that this is your problem.
Solution 2:
It's entirely possible that your ubuntu machine is getting a different network IP address than what is expected. Try the following:
- On the raspi, check its IP address with
ifconfig | grep 192.168
- on the ubuntu machine, check its IP address with
ifconfig | grep 192.168
In order to be able to talk to each other on your local network, they should both be using the same subnet - look at the third section of the IP address to see if they are. In your case, they should both be on the 192.168.2.* subnet.
Make sure they actually have different IP addresses too. This may seem obvious, but can happen if one of them is using DHCP and the other is set statically.
If that all checks out, then run the following command to see where your packets are supposed to be going:
route -n
Look in the output for the destination subnet that applies to your raspberry pi. There should really just be 3 rows:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
If you have more rows or things are going to weird spots, then that's the answer.
My guess is that your ssh connection is ending up hitting a different SSH server from the one on your raspberry pi, which is why changing the ubuntu firewall affected it and your logins aren't working.