Potential fix for enabling both eth0 and wlan0 at the same time on rpi4b

After borking up my pi a few times and a night of research on the forums and web, I had found numerous threads about not being able to have both Ethernet and WiFi enabled at the same time with DietPi. I think I found a workaround by adding this custom script to autostart option:

# DietPi-Autostart custom script
# Location: /var/lib/dietpi/dietpi-autostart/custom.sh

# Set the IP address of eth0 to
ip addr add dev eth0

# Enable the eth0 interface
ip link set dev eth0 up

# Remove the default route from eth0
ip route del default dev eth0

# Enable the wlan0 interface
ip link set dev wlan0 up

# Set the default route to on wlan0
ip route add default via dev wlan0

exit 0

It locks up after you enable eth0 for the first time, but after reboot both eth0 and wlan0 are enabled! Still messing with routes and stuff but so far it seems to be working, thought I would share. Hope this helps!

FWIW - I have wlan0 connected to home internet AP, and eth0 connected to a POE switch with IP cameras on the other end, and am planning to test motionEye with them. Still can’t ping the other end but am still playing with routes.

That’s not true. You can easily enable both at the same time. This is what we do for our Hotspot feature. There you have Ethernet connection to the internet and WiFi offered as Hotspot :slight_smile:

But your scenario is exactly the other way around. Use WiFi to connect to internet und Ethernet to connect to something else. However, it’s working to have both adapters up and running same time. Of course manual configuration steps needed to create a birded network between Ethernet and WiFi.

Well, it was true for me, for whatever reason. Both eth0 and wlan0 share the same subnet, I just had to add a route to the wired device via eth0 once both nics were up at the same time after the custom.sh runs on boot.

similar threads noting the problem i was experiencing: DietPi-Config | WiFi connection fails, when eth + wlan are enabled · Issue #2103 · MichaIng/DietPi · GitHub


Regardless, if it works for everyone else, fine, just posting a solution that worked for me here in case anyone runs in to a similar issue I experienced.


The GitHub issue is more than 4 years old. Same goes for the forum post.

On my test RPi4B, i’m able to connect to Ethernet as well as Wifi same time without issues

┌─────────────────────────┤ DietPi-Config ├─────────────────────────┐
│ Please select an option to change:                                │
│                                                                   │
│                         ●─ Adapter Options ──────────●            │
│            Ethernet     : Available | [On] | Connected            │
│            WiFi         : Available | [On] | Connected            │
│            Onboard WiFi : [On]                                    │
│                         ●─ Additional Options ───────●            │
│            IPv6         : [On]                                    │
│            Proxy        : [Off]                                   │
│            Test         : Run internet connection test            │
│                                                                   │
│                                                                   │
│                 <Ok>                     <Back>                   │
│                                                                   │

Both are connected to same local network

root@DietPi4:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether dc:a6:32:e2:10:cd brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic eth0
       valid_lft 86074sec preferred_lft 86074sec
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether dc:a6:32:e2:10:cf brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic wlan0
       valid_lft 86094sec preferred_lft 86094sec

The only thing specific for you is switching default gateway from Ethernet to Wifi.

Yes i think that’s the only real change going on (setting the default gateway back to wlan0 after enabling eth0) that i needed to do manually, otherwise as soon as i enabled eth0 via dietpi-config while connected to wifi, I wasn’t able to ssh in to the pi over wireless any longer because it set the new default route to eth0, which i didn’t want to do.

Thoughts? I can re-image my pi sometime this week and recreate this scenario if you like, otherwise this quick fix works fine for my use case.

yeah, by default the system will prefer Ethernet over WiFi. Therefore, you need to adjust default route within your setup.

No need. It’s fine if it is working in your special scenario.