-1

I'm trying to achieve two things, but they seem to be contradictory:

  1. I want to set a static ip on eth0 to be able to SSH into it from my Windows 10 Laptop via Ethernet cable. (I take my Rpi on the go, and I may not have network or be on an SSID which the Pi doesn't know)
  2. for wlan0 - I'd like the Pi to simply use DHCP from w/e router it's connected to. Ideally at the same time eth0 should still have the static ip so I can ssh in if wlan0 has problems.

from what I've read this can be done via /etc/dhcpcd.conf or /ect/network/interfaces, with the latter being deprecated and dhcpcd generally favored- so I'm trying to get dhcpcd to work.

Setting eth0 static ip works:

interface eth0
static ip_address 192.254.1.100

But then ifconfig shows wlan0 also uses 192.254.1.100 (which isn't in the router's subnet, so no network connection either)

I've tried setting

interface wlan0
dhcp

But that doesnt fix it. Setting a static ip:

wlan0
static ip_address 1.2.3.4

will set a different static ip for wlan0, but that doesn't solve my problem. Using specific ssids instead of wlan0 has the same effect.

If having static ethernet+dhcp wifi is a problem I could settle for some easy way to ssh into the pi with ethernet, but hostname didnt work for me so far.

Doesn't seem like it should be this hard to configure though, I'm new to this so hoping I'm just missing something simple :)

Raspberry Pi 3B with Buster

Jonathan Levin
  • 101
  • 1
  • 1

4 Answers4

2

You can Use systemd-networkd for general networking to solve your problem. Use section ♦ Create interface file for a wired connection and section ♦ Create interface file for a WiFi connection.

For the WiFi connection you can use the example as given. It uses DHCP by default.

For the wired connection comment option block: using a DHCP server and multicast DNS and uncomment option block: using static ip address and multicast DNS.

It should do then what you want.

Ingo
  • 42,107
  • 20
  • 85
  • 197
  • Will this require replacing the entire stock networking stack for systemd-networkd? Seems so from the abstract. In any case after a fresh install connecting by hostname is working for me, so I no longer need to have ethernet static – Jonathan Levin Nov 21 '20 at 22:38
  • "Will this require replacing the entire stock networking stack for systemd-networkd?" - Yes, Compare three available networking systems on Raspbian. – Ingo Nov 22 '20 at 00:48
  • @JonathanLevin Raspberry Pi OS comes with 3 networking systems installed. For wired networking with a router dhcpcd works out of the box. Debian networking requires /etc/network/interfaces(and disabling dhcpcd). In systemd-networkd you need to define network/s by creating .network files. To use wireless interfaces with any of these a helper program (WPA supplicant) is required, with its configuration files. All 3 work with standard settings and permit other options, BUT will do exactly what you tell them to do, and if this is wrong or impossible there will be no error messages. – Milliways Nov 22 '20 at 23:03
0

I did something similar a few days ago. Do you wan to route between ethernet and wifi interface?

On the static I think you are doing the right thing:

/etc/dhcpcd.conf
interface eth0
static ip_address=192.168.0.4/24    
static routers=192.168.0.254

By adding a static IP (witch can also be done from the GUI) you should be able to connect to the r-pi from your computer, as long as your computers' lan is also in the same network.

Documentation: https://www.raspberrypi.org/documentation/configuration/tcpip/

However if you want to connect to internet from you laptop using the pi as a router/access point take a look at this:

https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md

If that is the case you probably have to switch all lan0 and wifi0 settings from the documentation, so that wifi becomes the "wan-port", and the ethernet becomes "lan" on your setup.

A bit of topic, but if you are familiar with pro-networking, such as cisco networking you may install FRR. FR-Routing is a very cool routing platform that looks much like cisco that you may use on your pi. http://docs.frrouting.org/en/latest/

aboyum
  • 1
  • 3
0

After a while of scratching my head at wireshark and systemctl status dhcpcd.service, I decided to try a fresh install of Rpi-OS Lite.

Still can't get static eth0 + dynamic wlan0.. But it did somehow fix hostname resolution, so I can ssh with <hostname>.local now.

In retrospect this was probably the problem I should have pursued anyway, as it's much more flexible than a static ip.

Still curious as to why dhcpcd didn't work, but the problem is solved and I've learned a ton about networking along the way, so that's good enough for me :)

Jonathan Levin
  • 101
  • 1
  • 1
  • It does work, but as you haven't responded to the requests for information or explained anything about your network all you will get is speculation (at best). On most OS you don't need an IP Address to ssh over an Ethernet link. – Milliways Nov 21 '20 at 23:26
  • Apologies for not responding, I found some workarounds for finding my pi's ip without a terminal and so decided against a static ip entirely. As the OP stated the network structure is just a Windows 10 laptop -> pi with an ethernet cable, using Windows autoconfiguration. And yes ideally I would just ssh w/ hostname, but it's not working reliably for me atm. – Jonathan Levin Nov 23 '20 at 20:58
0

Adding this answer for anyone else that comes across this like I did. I needed a solution where the eth0 interface was static and the wlan0 interface was dynamic. After some trial and error, I set it like this and it's working:

sudo nano /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.25.100/24
static routers=192.168.25.1
static domain_name_servers=192.168.25.1 8.8.8.8

interface wlan0
[Intentionally left blank]

That's it. After a reboot, I was able to dynamically receive an IP while on WiFi. When I removed it from my WiFi and took to customer site and plugged in ethernet, it connected using the static IP.

Jeremy
  • 1
  • 1