Hi! I hope this is the right community to ask.

Next week I will be on the road for 5 Days for work. I have quite some spare time, so I thought I would dig up my raspberry project again and hopefully finish it.

I need it with me, because it controls some hardware, so a VPN to home does not work. So only option I could think of, is to connect the pi directly to my laptop via an ethernet cable. As far as I understood from some research is that I would need to install and run an DHCP server on my laptop, which they did not recommend. Alternatively they suggested to just take a router and plug both devices in there. I don’t really have a spare router, so that’s not an option either.

To be hones it confuses me a little, that there does not seem to be a standard for connecting to a device directly over a single cable and login with a user account.

Any recommendations how I can work on the pi like with ssh?

Thanks a lot!

  • rtxn@lemmy.world
    link
    fedilink
    English
    arrow-up
    32
    arrow-down
    2
    ·
    edit-2
    9 months ago

    Give each device a static address, and set the default gateway to whatever’s on the other end of the cable. You might need a crossover cable, but most NICs can work using a straight-through.

    E.g. set the laptop’s address to 169.254.1.1/16 and default gateway to 169.254.1.2, and the RPi’s address to 169.254.1.2/16 and default gateway to 169.254.1.1. They should be able to talk to each other then.

    If those addresses seem familiar - Windows uses the 169.254.0.0/16 subnet to automatically assign random addresses if DHCP fails, so that if there are several computers in the subnet, they’ll at least have addresses that can talk to each other. It’s called APIPA in Windows, and Zeroconf in the Unixverse.

    • AbidanYre@lemmy.world
      link
      fedilink
      English
      arrow-up
      11
      ·
      edit-2
      9 months ago

      You jump between 196 and 169 in your comment.

      It’s not just Windows that uses 169.254. That’s a special block used for self assigned link-local addresses.

      • thecrotch@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        9 months ago

        You would not. In the example given 169.254.1.1 doesn’t even exist, no machine is listening on that address so it couldn’t possibly do any good if it wanted to

    • thecrotch@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 months ago

      Setting the default gateway is unnecessary for a network of peers that are already on the subnet. It can only lead to problems as the hosts try to send every request outside their network to 169.254.1.1, which doesn’t even exist in this scenario

    • WbrJr@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 months ago

      Thanks! That seems rather easy. Only thing I’m not sure about, I have basically only access to the pi over SSH. I could use a screen and keyboard but would prefer not to. What would happen if I configure the network wrong on the pi and can not connect anymore, even over my home network? Could I change the config by putting the SD card into my laptop and changing a file? Or is it possible to make it redundant, so if it can’t find a DHCP server, it automatically switches to the preconfigured settings you described? :) Thanks a lot

      • Darkassassin07@lemmy.ca
        link
        fedilink
        English
        arrow-up
        3
        ·
        9 months ago

        Configure ethernet with fixed IPs, and configure wifi to use your phone hotspot.

        Then you can use one to troubleshoot the other as needed.

        Then your normal setup would be wired between the pi+laptop, with the laptop connected to local wifi for internet.

      • rtxn@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        9 months ago

        I’ve never used a pi, but it should be possible to mount the root partition and edit the /etc/network/interfaces or /etc/dhcpcd.conf file, or /etc/NetworkManager/conf.d/* if you have NetworkManager (systemctl status NetworkManager to check).

        You should also make sure that sshd is listening for connections from any address (0.0.0.0 and ::).

      • atzanteol@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        9 months ago

        Network interfaces can be assigned multiple IP addresses. You should be able to use DHCP and a link local address at the same time.

        That said I think this is easier to do with network manager. I’m not sure how it works with the rpi. But “link local address rpi” is a good search term to start with.

    • lemmyingly@lemm.ee
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 months ago

      Is there an easy method to know the self assigned IP address of the other machine if it’s run as headless?

      The only methods I can think of is using something like Wireguard to see what IP addresses are talking, or ping all 32k IP addresses to see which responds.

      • thecrotch@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        9 months ago

        The poster you’re replying to is suggesting a static IP in the apipa range, not an apipa assigned ip. You’d already know a static IP because you set it yourself.

      • rtxn@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        9 months ago

        Wireguard

        You mean Wireshark? It’s possible. You might even capture the DHCP exchange.

        The two best programs for the job are nmap and arp-scan.

        Nmap is like ping on steroids. You can use it for network discovery, port scanning, fingerprinting, and basic pentesting. As long as the pi can talk to the computer, nmap will sniff it out.

        ARP-scan works on the data link layer to identify hosts using ARP. It should be able to return the IP address of all ethernet devices even if they end up in different subnets. It took me a little over two minutes to scan a /16 subnet with one retry and 0.1 second timeout.

        If you are really concerned about the pi’s address, you should run a local DHCP server on the laptop. dnsmasq for Linux and Mac, but I have no idea what to use on Windows (other than a VM bridged to the ethernet interface).

    • WasPentalive@lemmy.one
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      1
      ·
      9 months ago

      Would the Pi automatically set an APIPA address if DHCP was not available? If so he need only connect the cable, and ask each machine what their address is.

      • rtxn@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        9 months ago

        No idea. It depends on what software it uses for network configuration, and how that software handles DHCP failure. I use NetworkManager and I’ve never gotten an APIPA address.

  • JASN_DE@lemmy.world
    link
    fedilink
    English
    arrow-up
    14
    ·
    9 months ago

    As far as I understood from some research is that I would need to install and run an DHCP server on my laptop, which they did not recommend.

    Or simply set up the Pi with a static IP.

    there does not seem to be a standard for connecting to a device directly over a single cable and login with a user account.

    There is. A cable. You just need two non-identical IPs from the same subnet, e.g. 10.0.0.1 and 10.0.0.2 or whichever you want from the private ranges.

    • lemmyingly@lemm.ee
      link
      fedilink
      English
      arrow-up
      2
      ·
      9 months ago

      I think this method should be the top answer.

      I connect directly to devices without a router most working days for work and this is the method we use because it’s simple and effective.

    • poVoq@slrpnk.net
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      9 months ago

      I remember from back in the day that you need a "twisted pair” edit: ”cross-over” cable though, or do modern ethernet ports automatically adapt to that now?

      • BearOfaTime@lemm.ee
        link
        fedilink
        English
        arrow-up
        5
        arrow-down
        1
        ·
        9 months ago

        Twisted pair refers to the twisting of the wires in the cable to reduce crosstalk.

        Crossover cables enable permit connecting two non-sensing ports together.

        • poVoq@slrpnk.net
          link
          fedilink
          English
          arrow-up
          3
          ·
          edit-2
          9 months ago

          Right 🤦‍♂️ It has been a while. I corrected it in the original post now.

          • BearOfaTime@lemm.ee
            link
            fedilink
            English
            arrow-up
            1
            arrow-down
            1
            ·
            9 months ago

            I hear ya. I know all this stuff, but dammit if it isn’t hard to access sometimes! Haha

        • rtxn@lemmy.world
          link
          fedilink
          English
          arrow-up
          4
          ·
          9 months ago

          Most modern NICs can auto-negotiate the Rx/Tx circuits on either kind of cable, but I’m not sure about RPi.

            • IsoKiero@sopuli.xyz
              link
              fedilink
              English
              arrow-up
              2
              ·
              9 months ago

              If I remember correctly, 1000Base-T standard has a requirement that device has to negotiate pinout on the fly. No matter which pin is connected to which. Obvioiusly just randomly wiring a cable up has other problems, like signal-to-noise, but in theory it should work even if you make a cable that’s as unstandard as you can make it.

              • jkrtn@lemmy.ml
                link
                fedilink
                English
                arrow-up
                1
                ·
                9 months ago

                That’s amazing. I would love to see the algorithm for that. Hopefully I’ll find a nice explainer if I search around.

      • kuneho@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        9 months ago

        I think it doesn’t matter nowadays. Network interfaces are smart enough to twist them internally, or at least, this is what I experienced. I have no idea when did I had to use specifically a crosswire cable, all of my ethernet cables are patch cables for a while now.

        So, it shouldn’t be a problem.

    • Bitflip@lemmy.ml
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 months ago

      This for sure, and bonus points for “USB Ethernet gadget” mode if you have a 4 or zero ;)

      • dadarobot@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        3
        ·
        9 months ago

        No, your laptop also connects to the hotspot. If you have available wifi at your location, you can then setup the pi to use that wifi and disconnect the phone hotspot, and just use the local wifi on all devices.

        Ive just found this to be the simplest setup. I briefly had serial over bluetooth set up, and it was an easier way to change the pi’s wifi, but it broke pretty quickly for me not sure why.

        Probably the most elegant solution is ethernet over usb, but thats a bit of a pain to set up.

        For me a hotspot has been the least headache

  • qjkxbmwvz@startrek.website
    link
    fedilink
    English
    arrow-up
    5
    ·
    9 months ago

    Does the raspberry pi have a wifi adapter, and is it unused for your project?

    If so, you can use your pi as an access point — no need for cables, you just connect your laptop to the pi’s SSID.

    Downside is that now your laptop doesn’t have Internet access, which may be a deal breaker (unless you can plug your pi into a router and get access through it). You could just get a cheap USB wifi dongle for your laptop and use one interface for Internet, one for pi.

    Hostapd is probably how you would go about this of you’re interested ( https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software )

    • DontNoodles@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      2
      ·
      9 months ago

      Or they could connect their pi as well as their laptop to a hotspot created on their pocket computer masquerading as a phone. They won’t lose their internet on the laptop or pi that way.

  • Decronym@lemmy.decronym.xyzB
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    9 months ago

    Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I’ve seen in this thread:

    Fewer Letters More Letters
    DNS Domain Name Service/System
    IP Internet Protocol
    RPi Raspberry Pi brand of SBC
    SBC Single-Board Computer
    SSH Secure Shell for remote terminal access

    4 acronyms in this thread; the most compressed thread commented on today has 6 acronyms.

    [Thread #538 for this sub, first seen 23rd Feb 2024, 13:35] [FAQ] [Full list] [Contact] [Source code]

  • sloppy_diffuser@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    9 months ago

    Can try installing Avahi on the RPi (may come on the default image). It will advertise .local over mDNS / DNS-SD. I believe Avahi will advertise on link local if there is no default route to the internet.

    Your system may automatically resolve the domain if its able to pickup the mDNS records to SSH in. Been a couple years since I’ve done it, so I could be forgetting a nuanced detail, but I vaguely remember just ‘plug and play’ if internet for the RPi wasn’t required.

  • bob@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    arrow-down
    1
    ·
    9 months ago

    It’s too difficult to connect devices in two intranets, if you don’t have a speed requirement, I think you can use tuntox