Possible to have both Wi-Fi and Ethernet connected to the same network?

I am running Arch Linux (on a Raspberry Pi 3) and tried to connect both the Ethernet and the Wi-Fi to the same network. route shows me the following:

$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    1024   0        0 eth0
default         gateway         0.0.0.0         UG    1024   0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0
gateway         0.0.0.0         255.255.255.255 UH    1024   0        0 eth0
gateway         0.0.0.0         255.255.255.255 UH    1024   0        0 wlan0

ip addr shows me the following:

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether b8:27:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.103/24 brd 192.168.1.255 scope global dynamic eth0
       valid_lft 85717sec preferred_lft 85717sec
    inet6 fe80::ba27:ebff:fee4:4f60/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether b8:27:YY:YY:YY:YY brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.102/24 brd 192.168.1.255 scope global dynamic wlan0
       valid_lft 85727sec preferred_lft 85727sec
    inet6 fe80::ba27:ebff:feb1:1a35/64 scope link
       valid_lft forever preferred_lft forever

Both wlan0 and eth0 interfaces were able to get an IP address from the router.

But it turns out that only one of these interfaces ever works. The other interface cannot be pinged and is not connectable. Usually it’s the Ethernet that works but sometimes it’s the Wi-Fi.

What’s happening? What can I do to make this work?

Asked By: rityzmon

||

As you have found out, from the routing perspective, while possible, it is not ideal to have addresses from the same network in different interfaces.

Routing expects a different network per interface, and ultimately one of them will take precedence over the other in routing, since they overlap.

The advised solution for having more than one interface connected to the same network is to aggregate them together in a bridge interface.

The bridge interface will "own" the IP address, and the actual real interfaces are grouped as a virtual single entity under br0.

allow-hotplug eth0
iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual

auto br0
iface br0 inet dhcp
    bridge_ports eth0 wlan0
    

Debian Linux: Configure Network Interfaces As A Bridge / Network Switch

Answered By: Rui F Ribeiro

This is more an addendum than a complete solution. [Since I don’t have enough “reputation points” to comment.]

You first have to make both interfaces work independently. Then, instead of bridging, you can also load balance outgoing connections across both interfaces.

https://www.tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.multiple-links.html

I started out with this, two devices with default route to the internet configured by network manager:

❯ ip route
default via 192.168.0.1 dev eno1 proto dhcp metric 100 
default via 192.168.0.1 dev wlp4s0 proto dhcp metric 600 
169.254.0.0/16 dev wlp4s0 scope link metric 1000 
192.168.0.0/24 dev eno1 proto kernel scope link src 192.168.0.246 metric 100 
192.168.0.0/24 dev wlp4s0 proto kernel scope link src 192.168.0.213 metric 600 

Then I used the command, described here under load balancing:

https://www.tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.multiple-links.html

❯ P1=192.168.0.1
❯ P2=192.168.0.1
❯ IF1=eno1
❯ IF2=wlp4s0
❯ ip route add default scope global nexthop via $P1 dev $IF1 weight 1      
            nexthop via $P2 dev $IF2 weight 1

Voala! I get connections through both devices.

❯ ip route                                                                  
default 
    nexthop via 192.168.0.1 dev eno1 weight 1 
    nexthop via 192.168.0.1 dev wlp4s0 weight 1 
default via 192.168.0.1 dev eno1 proto dhcp metric 100 
default via 192.168.0.1 dev wlp4s0 proto dhcp metric 600 
169.254.0.0/16 dev wlp4s0 scope link metric 1000 
192.168.0.0/24 dev eno1 proto kernel scope link src 192.168.0.246 metric 100 
192.168.0.0/24 dev wlp4s0 proto kernel scope link src 192.168.0.213 metric 600 

That might make debugging more difficult if I have connection trouble 😉

And I don’t know how to persist the configuration across reboots yet, especially in combination with network manager.

Answered By: Peter Kolloch