-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,961
  • 20
  • 87
  • 207
1

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
  • 11
  • 2
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