This is a typical failover scenario and this is handled
by bonding. You can find information at Debian -
bonding. Here for example I have made
a tested configuration with Raspbian on a Raspberry Pi 3 that will bond
eth0 and switch transparent between this two interfaces.
Who are interested for doing this with
systemd-networkd can look at Howto migrate from networking to systemd-networkd with dynamic failover.
For the old style networking you have to configure
/etc/network/interfaces but I couldn't get it together with dhcpcd.
It's too complicated with network/interfaces and dhcpcd and wpa-supplicant and resolvconf and bonding. So for this example I
disabled dhcpcd and use an old style networking configuration. First install needed packages:
pi@raspberrypi:~ $ sudo apt install ifenslave
pi@raspberrypi:~ $ sudo apt install resolvconf
Then setup /etc/network/interfaces like this:
pi@raspberrypi:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
# bond eth0 together with wlan0
# for status look at: cat /proc/net/bonding/bond0
iface bond0 inet static
bond-slaves wlan0 eth0
iface wlan0 inet manual
You should give this file
chmod 600 /etc/network/interfaces.
spi@raspberrypi:~ $ sudo systemctl stop dhcpcd
spi@raspberrypi:~ $ sudo systemctl disable dhcpcd
cat /proc/net/bonding/bond0 if it's working.