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

arch linuxethernetnetwork-interfacenetworkingwifi

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?

Best Answer

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

Related Question