0

Can a single REAL Ethernet interface be addressed on (2) DIFFERENT subnets?

But how can this be when a Pi only has a single REAL interface- and therefore only a single MAC address to map the (2) different IPs to?!?!?

I've recently seen confusion and outright wrong info put out in this forum about multi-homing a Pi's single interface. So as I imagine this to be a common misconception and an issue of broad interest given increase in POE connectivity of Pi users, I'll give a granular example which illustrates that it both CAN be done as well as HOW to accomplish it.

1

Short answer here from a networking perspective is VLANs and is not dependent on a Pi.

This will give you anything up to 4096 different logical network interfaces which function the same as physical interfaces, from the point of view of the OS/kernel and software.

The downside is that you will need a managed switch that understands VLANs, or a direct ethernet to a firewall/router device that also understands VLANs. A home-grade route will not be adequate, you'd need a firewall like pfsense or myriad of other soho devices.

The OS will see eth0 as the physical interface, and each VLAN will appear in the format of eth0.90 for VLAN ID number 90.

# ip address show
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
   inet 169.254.1.1/24 brd 169.254.255.255 scope global eth0
3: eth0.10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
    inet 10.229.10.1/20 brd 10.229.15.255 scope global eth0.10
4: eth0.20: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
   inet 10.229.20.1/22 brd 10.229.23.255 scope global eth0.20

The above host has 3 networks on the one port. Untagged (IE normal LAN) is in the zeroconf range. There are VLAN IDs 10 and 20, coinciding with the third octet of the IPv4 address for neatness.

Note: This setup does not allow a host on one VLAN to talk through your PI to a host on another VLAN. That would be IP Routing and is a whole-separate question.


More info on VLANs: https://www.reddit.com/r/homelab/comments/a94oka/learn_with_me_ep1_introduction_vlans_pfsense/

https://help.ubnt.com/hc/en-us/articles/222183968-Intro-to-Networking-Introduction-to-Virtual-LANs-VLANs-and-Tagging

0

Having multiple interfaces on a host addressed within the same subnet can cause a networking issue called "ARP Flux" and is to be avoided.

So not only is it POSSIBLE to join different interfaces to different subnets, it's IMPLIED when multi-homing a host not to address multiple interfaces within the same subnet. And as this example demonstrates, you do NOT require (2) nics each with a different MAC address.

And this can be accomplished WITHOUT A VLAN, only using a static route. The below example is tested and known to work correctly. If you have a couple of small switches and a Pi, you too can actually try this out quite easily.

SETUP:

Using (2) different /28 subnets- sensibly sized for a pair of 8 port switches- our specimen networking is organized as follows:

Switch 1: 192.168.1.0/28

Switch IP:          192.168.1.1/28
Router Interface:   192.168.1.2/28
Assignable IPs:     192.168.1.3-14

Switch 2: 192.168.1.16/28

Switch IP:          192.168.1.17/28
Router Interface:   192.168.1.18/28
Assignable IPs:     192.168.1.19-30

Raspberry Pi:

Has a physical connection to Switch 1

We'll assign last IP in each subnet to Pi:

192.168.1.14 (Switch 1)
192.168.1.30 (Switch 2)

There are several ways we can address our single eth0 interface, discussed after next section "ROUTING"

ROUTING:

Only static IPs configured: DHCP disabled on router interfaces the switches are connected to

Switch 1 has a direct connection to router which routes all traffic for switch 1's subnet 192.168.1.0/28 to it. Since 192.168.1.14 is within Switch 1's routed subnet, no static route is required for this address.

HOWEVER: Since the Pi's other IP 192.168.1.30 is within Switch 2's subnet, by default traffic for this IP will be routed to Switch 2 causing connections to fail. Routers route traffic from MOST specific to LEAST specific route: a static route pointing to a host will be used before one pointing to a subnet.

Add a static route on router:

Destination Address:    192.168.1.30/32     (Interface of Pi OUTSIDE switch's routed subnet)
Gateway Address:        192.168.1.14        (interface of Pi INSIDE switch's routed subnet)

Note we are NOT using router's interface to Switch 1 192.168.1.2, but IP of Pi within routed subnet of Switch 1. Once traffic arrives at Pi, it knows that it's the destination for 192.168.1.30.

Once static route added, host can be accessed on either address: 192.168.1.14 (subnet 1) and 192.168.1.30 (subnet 2)

ADDRESSING:

Couple of ways- maybe not the only ones- to assign addresses on the single eth0 interface:

Method 1: /etc/dhcpcd.conf & /etc/rc.local

/etc/dhcpcd.conf

Use the IP within switch 1's routed subnet:

interface eth0
static ip_address=192.168.1.14/28
static routers=192.168.1.2
static domain_name_servers=8.8.8.8

/etc/rc.local

Add following command to rc.local

/sbin/ip addr add dev eth0 192.168.1.30/28

NOTE: Interface(s) added via rc.local will survive "systemctl restart networking"

Method 2: /etc/network/interfaces.d/

/etc/network/interfaces

Change FROM:

source-directory /etc/network/interfaces.d

TO:

source /etc/network/interfaces.d/*

Next, create (2) files with your addressing details:

/etc/network/interfaces.d/eth0

auto eth0
iface eth0 inet static
address 192.168.1.14
netmask 255.255.255.240
network 192.168.1.0
broadcast 192.168.1.15
gateway 192.168.1.2

/etc/network/interfaces.d/eth0:0

auto eth0:0
iface eth0:0 inet static
address 192.168.1.30
netmask 255.255.255.240

Anyhoo, if you have a use-case that requires multi-homing, hope this post helped you-

  • This is known by the name "overlay network" The main difference between this and vlans is security - that hosts can still see broadcast traffic in the other network, and nothing stops a user changing their IP to fall within the other range. Perfectly acceptable, if you trust all your users and devices. – Criggie Mar 18 at 20:45
  • I limited the scope of my post to configuring host networking within Linux, with the small exception of setting a static route on the router. No dependencies on specific network hardware and its' configuration; just Linux. This ensures that a reader with a bog-standard pair of switches, a plain-vanilla router and a Pi can achieve connectivity on (2) subnets with a single interface. – F1Linux Mar 19 at 2:55
  • 1
    fair enough - so why post this in raspberrypi and not linux/unix stack? There's nothing here that is unique to a Pi. – Criggie Mar 19 at 7:26
  • As I stated in the question, the incorrect info-that an IF couldn’t be addressed on 2 subsets w/out a clan- was put out in this forum; this was best place to address it. And as Pi is a Linux system, discussing Linux config is within the scope of this forum. Finally, as a Pi has just a single real IF, seemed likely that aliasing Ethernet interfaces would be a common requirement beginners would need a hand with – F1Linux Mar 19 at 17:25
  • This setup has nothing to do with the OSI model which is used to standardize communication of computing systems. It may break or mix up well defined protocols based on the OSI model. In this case it breaks OSI layer 2 because 192.168.1.30 is not part of the broadcast domain 192.168.1.16/28. Simple question: how will 192.168.1.30 find its neighbors? ARP broadcasts are not routed. I cannot recommend using this setup. – Ingo Mar 19 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.