TransWikia.com

How do I control a headless Raspberry Pi 3 b+ via SSH from Ubuntu 18.04 LTS without a router?

Raspberry Pi Asked by Matt Lyons on November 11, 2021

There are many variations of this question that I’ve found on this site, but so far I haven’t found an answer that solves my exact use case.

Currently, I am able to SSH into my Raspberry Pi 3 b+ (running Raspbian Stretch Lite) from my laptop (running Ubuntu 18.04 LTS) using an ethernet cable connected to a router, which is then connected to the Raspberry Pi via ethernet as well. To make this possible, I added an empty file named “ssh” to the boot directory of the Pi.

Specifically, I use the command:

ssh pi@<ip_address>

to connect to the raspberry pi. I obtain the IP address of the Pi every time by entering the router IP into my web browser, which is 192.168.0.1. Then, I’m able to execute whatever I want from the command line on the Pi.

Now, the problem with this setup is that I don’t want to carry the router around anymore, as it takes up too much space in my backpack. I want to have the same level of control over the Pi, but without the router. Also, obviously I don’t want to use and HDMI cable, monitor, and external keyboard and mouse either, as I could not feasibly carry all these components in my backpack.

So: Is there a way I can control the Raspberry Pi in virtually the same way I am now, with only using my laptop and an ethernet cable?

4 Answers

You can use link-local addresses together with mDNS (multicast Domain Name Service). Default Raspbian Stretch is doing it out of the box. To check just connect the RasPi to the Laptop with an ethernet cable and ensure that there is no DHCP server running:

rpi ~$ ip -4 addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 169.254.89.120/16 brd 169.254.255.255 scope global eth0
       valid_lft forever preferred_lft forever

169.254.89.120/16 is from the address block 169.254.0.0/16 for link-local addresses. Then check if name resolution works by pinging its own mDNS name (just wait a bit):

$ ping raspberrypi.local
PING raspberrypi.local (169.254.89.120) 56(84) bytes of data.
64 bytes from raspberrypi.local (169.254.89.120): icmp_seq=1 ttl=64 time=0.076 ms
64 bytes from raspberrypi.local (169.254.89.120): icmp_seq=2 ttl=64 time=0.053 ms
64 bytes from raspberrypi.local (169.254.89.120): icmp_seq=3 ttl=64 time=0.043 ms
--- snip ---

Works.

Now to the Ubuntu Laptop. I don't have Ubuntu running so I cannot say exactly what to do. If you have dhcpcd running then you should nothing have to do like on the RasPi.

If you have systemd-networkd running then just add a line LinkLocalAddressing=yes to the eth0 interface file, for example:

rpi ~$ cat /etc/systemd/network/04-eth.network
[Match]
Name=e*
[Network]
DHCP=yes
LinkLocalAddressing=yes

Otherwise you should have avahi-autoipd installed with:

rpi ~$ sudo apt install avahi-autoipd

As already said I couldn't test it. I hope it works as expected. Anyway you have always to install the avahi-daemon. It will do name resolution with mDNS:

rpi ~$ sudo apt install avahi-daemon

Now the eth0 interface should also have a link-local address and you should be able to ping the laptops own interface using its laptop name, maybe ping myubuntu.local and you should be able to ping raspberrypi.local.

This should also work with DHCP. If a DHCP server is present they will use it, otherwise they will use a link-local address.

Answered by Ingo on November 11, 2021

There are 3 possible solution I already use, depending on situation:

1) Assign to laptop wired Ethernet port static IP address like 192.168.99.1/24, assign RPi Ethernet port static IP address like 192.168.99.2, connect laptop to RPi by wire, next "ssh [email protected]" (as @php_nub_qq stands)

2) install on Ubuntu dnsmasq package, that is DNS/DHCP bundle package. Assign in dnsmasq config file static association of RPi MAC address to IP and as option to mnemonic name. So You will be able to "ssh pi@name_of_RPi".

3) If You want to use WiFi as connection between laptop and RPi, install additionally hostapd package on Ubuntu. Next use solution from point 1 or 2 but without cable but via WiFi.

Answered by mackowiakp on November 11, 2021

You can define static IPs on your network adapters and they will be able to talk to each other. This is extremely simple to do in command line

On laptop

sudo ip ad add 10.0.0.10/24 dev eth0

On raspi

sudo ip ad add 10.0.0.20/24 dev eth0

To test from laptop to raspi

ping 10.0.0.20

To test from raspi to laptop

ping 10.0.0.10

You might need to correct your adapter names.

Detailed answer here.

Answered by php_nub_qq on November 11, 2021

You can access the Pi at ssh [email protected]

See "Connecting a Computer to the Pi" in How to set up networking/WiFi

Answered by Milliways on November 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP