auto switch interface

Kernels & Hardware, configuring network, installing services

auto switch interface

Postby Bouwser » 2018-06-01 14:54

Hello,
I have an Single Board computer (SBC) running Debian Stretch with 2 ethernet ports and a cellular connection. The first Ethernet port is configured to connect to a network as DHCP. The second Ethernet is configured to act as a DHCP server to allow a technician to come up and plug into it in the field if necessary. This second Ethernet port is not made accessible to the customer and is rarely used. I will be ignoring this Ethernet port in my scenarios below. This SBC is a product that could end up in a variety of situations. I would like it to do the following...

1. If just the Ethernet is connected, and the USB cell modem is not plugged in, then use the Ethernet port to route messages to the internet.
2. If just the USB cell modem is plugged in and the Ethernet is not, use the cell modem to route messages to the internet.
3. If both the Ethernet and cell modem are plugged in, use Ethernet to route messages to the internet.
4. If both the Ethernet and cell modem are plugged in, but then the ethernet is unplugged switch to using the cellular modem to route messages to the internet.
5. If just the cell modem is plugged in and then the Ethernet is plugged in, switch to using the Ethernet to route messages to the internet.

I currently am able to do 1 - 3, but not 4 & 5. Is there a way to detect if an interfaces appearing and going away and then re-route messages to the preferred interface?

Here is my current interfaces file...
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

#source /etc/network/interfaces.d/*

#The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp2s0
allow-hotplug enp2s0
iface enp2s0 inet dhcp
gateway 192.168.150.1 #Gateway for Ethernet must be defined if you want to default to this interface vs cellular.

#Cellular Interface
auto enp0s20u1
allow-hotplug enp0s20u1
iface enp0s20u1 inet dhcp

# The secondary network interface
auto enp3s0
allow-hotplug enp3s0
iface enp3s0 inet static
address 192.168.175.1
netmask 255.255.255.0
broadcast 192.168.175.255
network 192.168.175.0


dns-nameservers 8.8.8.8 8.8.4.4
post-up iptables-restore < /etc/iptables.up.rules
#post-up route del default dev $IFACE #this is required if no gateway is specified for enp2s0

thanks in advance,
Brent
Bouwser
 
Posts: 10
Joined: 2014-09-04 14:12

Return to System configuration

Who is online

Users browsing this forum: Olive and 3 guests

fashionable