0

I'm trying to connect to my Pi over ssh while connected directly with ethernet - but I can't.

I have my Pi, which I connect to the PC over ethernet directly. Problem is - the PC stopped seeing the Pi. Here are some tests that I run:

ifconfig on the PC:

enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.42.0.1  netmask 255.255.255.0  broadcast 10.42.0.255
        inet6 fe80::36db:997a:ac32:11a8  prefixlen 64  scopeid 0x20<link>
        ether 00:2b:67:64:60:41  txqueuelen 1000  (Ethernet)
        RX packets 4  bytes 814 (814.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 31  bytes 4790 (4.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

nmap scan on the PC:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-06-16 08:50 CEST
Nmap scan report for ThinkPad (10.42.0.1)
Host is up.
Nmap done: 256 IP addresses (1 host up) scanned in 10.54 seconds

ifconfig on the Pi:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
      inet 169.254.71.238 netmask 255.255.0.0 broadcast 169.254.255.255
      inet6 fe80::c15b:7164:30b1:d79 prefixlen 64 scopeid 0x20<link>
      ether d8:3a:dd:0f:72:9d txqueuelen 1000 (Ethernet)
      RX packets 7 bytes 1228 (1.1 KiB)
      RX errors 0 dropped 0 overruns 0 frame 0
      TX packets 47 bytes 7021 (6.8 KiB)
      TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

I've also tried manually setting the IP address on the Pi, but to no avail:

ifconfig on the Pi:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.42.0.116  netmask 255.255.255.0  broadcast 10.42.0.255
        inet6 fe80::f283:6fd7:3316:cf3f  prefixlen 64  scopeid 0x20<link>
        ether d8:3a:dd:0f:72:9d  txqueuelen 1000  (Ethernet)
        RX packets 4602  bytes 655025 (639.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3675  bytes 744521 (727.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

but the nmap scan on the PC shows nothing:

$ nmap -sn 10.42.0.255/24
Starting Nmap 7.80 ( https://nmap.org ) at 2023-07-12 10:12 CEST
Nmap scan report for ThinkPad (10.42.0.1)
Host is up (0.00057s latency).
Nmap done: 256 IP addresses (1 host up) scanned in 3.10 seconds

and the same goes for the nmap scan on the Pi:

$ nmap -sn  10.42.0.255/24
Starting Nmap 7.80 ( https://nmap.org ) at 2023-07-12 10:15 CEST
Nmap done: 256 IP addresses (0 hosts up) scanned in 0.03 seconds

I can connect to the Pi when I connect it via a router, and another PC can just simply connect to the Pi via ethernet directly (the difference between the PCs is the OS - I'm using Ubuntu 22.04, the other PC is using 20.04). Pi is running bullseye.

Any help would be appreciated, as I don't really know what to do next. I think it's a PC problem (a config related one), but I have no idea what I could do. I've already set the the IPv4 and IPv6 method to be 'shared to other computers' on the PC.

Edit: As per suggestions, I've once again manually set the IP address on the Pi ifconfig eth0 10.42.0.116 netmask 255.255.255.0 and run ifconfig eth0 up. The nmap scan on the PC still didn't see the Pi. I've also run netstat -rn on the PC:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlp4s0
10.42.0.0       0.0.0.0         255.255.255.0   U         0 0          0 enp2s0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 wlp4s0

And I've run netstat -rn on the Pi:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

So it seems like the IP address I'm trying to set didn't actually set? And there is another network on 169.254.0.0 netmask 255.255.0.0 that the ifconfig on the PC didn't show me? Btw here both the PC and the Pi are connected to the same WiFi, but this is just for troubleshooting and will not be available 'in the field'.

Edit again: Complete output of ip addr from the Pi with the self-assigned address:

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether e4:5f:01:a6:68:ff brd ff:ff:ff:ff:ff:ff
    inet 169.254.240.210/16 brd 169.254.255.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::7102:dc3:1a73:1aab/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether e4:5f:01:a6:69:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.196/24 brd 192.168.1.255 scope global dynamic noprefixroute wlan0
       valid_lft 7135sec preferred_lft 6235sec
    inet6 fe80::1796:1cb:7078:19cd/64 scope link 
       valid_lft forever preferred_lft forever
6
  • @Milliways I do need to be able to connect to it directly, as it's used 'in the field'. I tried the router for troubleshooting purposes. Commented Jul 17, 2023 at 7:28
  • 1
    You really need to revise your question and explain WHAT YOU ARE TRYING TO DO, not ask about your attempted solution.
    – Milliways
    Commented Jul 17, 2023 at 7:34
  • @Milliways Ok, I've edited. Commented Jul 17, 2023 at 7:36
  • Yes, ssh is enabled. As you can CLEARLY SEE IN THE POST - it gets some random IP address that's not in the PC's range: the Pi's IP over ethernet: 169.254.71.238 while the PC's IP and netmask are: 10.42.0.1 netmask 255.255.255.0. And the error I get when I try to ssh using this random IP is no route to host. How I'm trying to connect is ssh pi@IP-address which would be ssh [email protected]. Commented Jul 17, 2023 at 7:55
  • My last attempt - try ssh [email protected]
    – Milliways
    Commented Jul 17, 2023 at 8:00

3 Answers 3

2

The entry I see for the route table on the Pi looks problematic to me.

Anytime a host needs to contact another host, it needs to determine some things:

  1. is the destination host on the same subnet as the source host?
  2. if yes, which network interface should be used to reach the host?
  3. if no, which gateway should be used to reach the host -- and which interface can reach that gateway?

With this in mind...

The PC has an address of 10.42.0.1/24 (netmask=255.255.255.0) on interface enp2s0.

ALSO the PC has a route table entry that says to reach the 10.42.0.0/24 network, use interface enp2s0.

So both those are are fine. This means if the PC wants to reach any host with an IP address starting 10.42.0.xxx then it can reach that machine directly (it does not need to use a gateway) AND the network interface that can reach that machine is enp2s0.

The Pi, on the hand, is not fine.

The Pi is taking on a self-assigned address on the 169.254.0.0/16 network and also creating a route table entry that says to reach the 169.254.0.0/16 network, use interface eth0.

This is likely happening because the Pi is looking for a DHCP server on the eth0 interface, and finding none, it resorts to a self-assigned address.

You then assigned it a static address of 10.42.0.116 -- which is fine.

BUT ... your netstat -rn output shows there is no entry in the route table that tells the Pi how to reach the 10.42.0.0/16 network.

THIS MEANS that the Pi is told that any machine with an IP address that starts with 10.42.0.xxx is directly reachable -- no gateway is needed. EXCEPT ... when it looks at the route table, there is no entry that tells it which network interface is connected a 10.42.0.0/24 network. So it doesn't know what to do.

You need to create a route entry. There are a couple of ways to do this. One is:

ip route add 10.42.0.0/24 dev eth0

Another is:

route add -net 10.42.0.0 netmask 255.255.255.0 dev eth0

While I suspect this will likely resolve your issue ... the issue only shows up because you didn't get a route table with an appropriate entry for that network because you manually added the IP address but not the route table entry. If there is not an appropriate DHCP server available on that subnet, then the better solution would be to configure the Pi to use a static address and not allow it to attempt to use DHCP ... and then fall-back to the self-assigned IP and route table entry.

2
  • This did the trick, however I'd like to use your 'better solution', how do I configure the Pi to use a static address? Will it then work every time (even after reboot or with a working DHCP server)? Commented Jul 19, 2023 at 6:04
  • @robotanical: If you're using dhcpcd, there's a pretty clear description on configuring a static IP address in man dhcpcd.conf.
    – Seamus
    Commented Jul 19, 2023 at 6:41
1

I am getting a bit puzzled about your questions and your comments. I therefore put some conclusions and further debugging info in an answer, hoping it will help you.

For the pc, I see that you use 10.42.0.1 with netmask 255.255.255.0.

For the Pi, I see an APIPA address 169.254.71.238 with netmask 255.255.0.0

These two devices are on different subnets. They can therefore not communicate directly. The fact that this does not work is normal.

Further on, you set the IP address of the Pi manually to 10.42.0.116 with netmask 255.255.255.0. Now, the PC and the Pi are on the same network. They should be able to connect. But your nmap 10.42.0.0/24 apparently does not see the Pi. From the Pi, it does not even show the Pi being up.

Things to try first: On the Pi, ping -c3 10.42.0.116. Does that provide results? If not, your interface is not correctly configured. It may be something as simple as ifconfig eth0 up, but you might find some additional info in the logs.

Routing may also be a problem. netstat -rn will tell you where the packets go to. I've seen people using the same subnet for their point-to-point connection as their normal network. That will of course also not work. This is for both the PC and the Pi.

In the comments, you insist on using the APIPA address, 169.254.71.238. As I explained earlier, your PC interface is not on that subnet, and therefore it will never work.

--- edit ---

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlp4s0
10.42.0.0       0.0.0.0         255.255.255.0   U         0 0          0 enp2s0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 wlp4s0

This shows why you cannot access the 169.254 network on your eth0 interface on the PC. The PC thinks that that subnet is connected to your wifi adapter.

Your Pi seems to be connected to WiFi and is on the same subnet as your PC. Is that the same network? If so, the Pi should be accessible via that network.

It seems indeed that the IP address in the 10.42.0-network is not on your ethernet interface. That would be a reason why you cannot communicate with the Pi. Add the complete ifconfig output (or the output of ip addr) on the Pi to your question.

--- edit 2 ---

So it is clear that you do not have the correct IP address on the eth0 of the Pi. That needs to be fixed first.

For a quick try, sudo ifconfig eth0 10.42.0.116 netmask 255.255.255.0 on the will do (or sudo ip addr add 10.42.0.116/24 dev eth0), but that is not permanent. If that works, add the appropriate lines to /etc/dhcpcd.conf.

6
  • If you have any suggestions as to what I can add to the question to make it more clear I'll be happy to oblige. I'm new to this and I'm not entirely sure what is needed to help, as I don't want to spam some unrelated info. I've edited to show the output of your suggestion and I'm even more confused. Hope you will know what to do with this? Commented Jul 18, 2023 at 6:32
  • See my addition to the "answer". Commented Jul 18, 2023 at 10:37
  • I've edited, but I'm unsure if you wanted the ip addr output before or after manually assigning the IP address? Commented Jul 18, 2023 at 10:54
  • For edit 2:As I say in the post, that's how I changed the IP address on the Pi - did not work. Commented Jul 19, 2023 at 5:45
  • Why not? Was there an error message? Did the logs say anything? Did it work a short time before some network-manager kicked in? Otherwise try the dhcpcd.conf-method and reboot. Set the IP address as static in dhcpcd.conf. Commented Jul 19, 2023 at 8:36
0

If you remove ALL settings you did on the Pi and remove `shared to other computers' you might have some success.

If you enable ICS you can NOT connect to the Pi but the Pi would have internet access via the PC.

What do you mean by connect to the Pi via ethernet?

If you connect by Ethernet you can ssh to the Pi (assuming you have enabled ssh) with:-

ssh username@hostname.local (substitute your username and hostname).

Forget deprecated ifconfig use ip a && ip r

5
  • Your answer answers nothing. I can't ssh into the Pi, because the PC doesn't see it on the network. I removed the 'shared to other computers' setting as well, but it didn't work (the setting is on the PC btw, as you seem to have no idea what I'm talking about). What setting do I remove from the Pi? I literally did nothing on it. What is ICS? And what does using ip a && ip r change in this context? Commented Jul 17, 2023 at 7:14
  • But you stated "I've also tried manually setting the IP address on the Pi" ICS is Internet Connection Sharing - variously called by other names depending on OS - I am assuming 'shared to other computers' is what enables it on your PC.
    – Milliways
    Commented Jul 17, 2023 at 7:20
  • Ah right, my fault. I did try to connect normally, before setting the IP manually, but it did not work, as you can see in the post. Hence why I set the IP address manually. And I tried that with and without the ICS on then. And after I set the IP manually I tried it with and without ICS. Nothing let me see the Pi on the network. Commented Jul 17, 2023 at 7:27
  • If you have a direct connection you will NOT "see the Pi on the network" because it isn't connected to any network - only the PC and Pi will see the link.
    – Milliways
    Commented Jul 17, 2023 at 7:32
  • Then maybe I'm not making myself clear. The nmap doesn't see it. I can't ssh into it. I can't ping it. How else should I phrase it so it's understandable? Commented Jul 17, 2023 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.