-1

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?

Matt Lyons
  • 31
  • 1
  • 5
  • You could set a static ip on the pi and connect it directly though you might also need to do the same on your laptop and im not completely sure how you need to set up your network interface such that it could both have a static ip and also get an assigned ip when its connected to a network. For sure you could look it up there is plenty of information just search for 'direct lan linux network interface setup' something along tbose lines. – php_nub_qq Feb 20 '19 at 08:57
  • Or you could configure a dhcp server on your laptop, but seems overkill for what you want. – php_nub_qq Feb 20 '19 at 08:58
  • running a dhcp server on your laptop would give you the ability to assing an ip to your pi, by connecting it via ethernet to your laptop. a more elegant solution to me would be if you use the inbuild wifi adapter of your pi as access point for your laptop or any other device that should communicate directly to your pi. This way you can place your pi anywhere you just need electricity. https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md – AlexOnLinux Feb 20 '19 at 10:27

4 Answers4

0

You can access the Pi at ssh pi@raspberrypi.local

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

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Just tried it, I get the error "ssh: Could not resolve hostname raspberrypi.local: Name or service not known" – Matt Lyons Feb 20 '19 at 09:18
0

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.

php_nub_qq
  • 225
  • 1
  • 9
0

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 pi@192.168.99.2" (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.

mackowiakp
  • 141
  • 3
  • I tried number 2, but I couldn't get it to work. I got the MAC address of the Pi using the command `cat /sys/class/net/eth0/address`. Then, I edited "/etc/dnsmasq.conf" to follow the format from line 232 of the file, to assign a host name to the MAC address. I wrote `dhcp-host=,raspi-local`. Expecting raspi-local to be the new host name. But still, using `ssh pi@raspi-local` didn't work, I get the error that it couldn't resolve the host name. Do I need to update "/etc/hosts" as well? Sorry I'm new to this. – Matt Lyons Feb 26 '19 at 03:50
0

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.

Ingo
  • 40,606
  • 15
  • 76
  • 189