2

I'm trying to connect the raspberry to the ethernet and wifi at the same time, but don't work.

Raspberry infos:

Model: Pi Model 3B+ V1.3

/etc/dhcpcd.conf:

# A sample configuration for dhcpcd. See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private

# Example static IP configuration:

interface eth0
static ip_address=10.10.7.201/21
static routers=10.10.0.1
#static domain_name_servers=
#static domain_search=

/etc/network/interfaces:

#iface default inet dhcp
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

/etc/wpa_supplicant/wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=it

network={
        ssid="xxxx"
        scan_ssid=1
        proto=RSN
        key_mgmt=WPA-PSK
        psk="xxxx"
        id_str="home"
        pairwise=CCMP TKIP
        group=CCMP TKIP
        priority=5
}

Network description

I need to connect both because:

  • The wifi provide network connectivity for ssh and internet (DHCP)
  • The ethernet connect to the local network and communicate with a PLC (Programmable logic controller) (Static IP: 10.10.7.201)

Network image

Actually my laptop is temporarily connected to both the network because the PLC needs to be programmed, so I have connected all to my laptop.

As asked in the comments:

The Raspberry is connected wireless as client uplink to the internet router. It does not provide an access point. On the ethernet side there is a device wired connected to the Raspberry. The wired subnet is local and has no connection to the internet. I can confirm that.

  1. Are there more devices on the wired subnet using a switch?

    On the switch there are connected:

    • Raspberry as 10.10.7.201
    • PLC as 10.10.7.200
    • MyLaptop as 10.10.7.3
  2. Are there other devices wireless connected to the internet router?

    Yes, there are many devices (It is the company network)

  3. Should wireless connected devices communicate with wired connected devices?

    No, the Raspberry is the only one device that must access the wired connected device (PLC). Essentially I have a Python flask webserver on the raspberry that act as interface between the user that connect to the webpage (using the wirless raspberry IP) and the PLC (That is on the wired connection)

  4. ip r output:

    default via 10.10.0.1 dev wlan0 proto dhcp src 10.10.4.195 metric 200 
    10.10.0.0/21 dev wlan0 proto dhcp scope link src 10.10.4.195 metric 200
    

Problem Description

The problem is that when I connect the Ethernet cable, the raspberry is unreachable on the WiFi network and can't access the internet from it, but both seems to be connected ifconfig:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.7.201  netmask 255.255.248.0  broadcast 10.10.7.255
        inet6 fe80::2fc5:49ad:9818:aaa0  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:bf:5a:f8  txqueuelen 1000  (Ethernet)
        RX packets 5364  bytes 388068 (378.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8582  bytes 501093 (489.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3154  bytes 524871 (512.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3154  bytes 524871 (512.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.4.195  netmask 255.255.248.0  broadcast 10.10.7.255
        inet6 fe80::f7bc:436f:a335:bff9  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:ea:0f:ad  txqueuelen 1000  (Ethernet)
        RX packets 61566  bytes 10678751 (10.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 4374 (4.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

When I diconnect the ethernet cable, the raspberry is reachable on the wifi connection and I can connect to it using SSH.

Attempts

I have looked on google how to setup both simultaneously and I have found this article, it is very old, but as you can see in the comment it should work.

NOTE:

  • /etc/network/interfaces is not actually used on the new raspberry, so I have edited the /etc/dhcpcd.conf instead.
  • /etc/default/ifplugd doesn't exist, so I have tried to install it apt-get install ifplugd and cofigured as in the answer, I have also added the line in /etc/rc.local.

Question

Do you have any tips for me on how I can correctly setup both connection to work?

I have tried to edit the /etc/dhcpcd.conf file to set the metric:

interface eth0
static ip_address=10.10.7.201/21
metric 300
#static routers=10.10.0.1
#static domain_name_servers=
#static domain_search=

interface wlan0
metric 200

Now the WiFi is reachable but not the ethernet cable, maybe I'm missing some route add command to perform?

  • Just to understand your network: the RasPi is connected wireless as client uplink to your internet router. It does not provide an access point. On the other side there is a device wired connected to the RasPi. The wired subnet is local and has no connection to the internet. Can you confirm this please? Are there more devices on the wired subnet using a switch? Are there other devices wireless connected to the internet router? Should wireless connected devices communicate with wired connected devices? – Ingo Oct 5 at 9:25
  • Hi @Ingo, thanks for you time, I have updated the question to include more details, take a look to the Network description section. – Carlo Zanocco Oct 5 at 9:35
  • Hi @Milliways I'm building a webserver on the raspberry using flask python. The end user need to connect to the raspberry WiFi IP and use the webpage to control the PLC device that is on the ethernet network. Actually I'm developing it, so the network is the company network. I have one laptop with two ethernet cable, one that is in the network where the rasp is connected over wifi, the second cable connected to the switch with the raspberry ethernet and the PLC. – Carlo Zanocco Oct 5 at 9:38
  • @CarloZanocco you need to explain in more detail what the networks do. Post the output of ip r – Milliways Oct 5 at 9:41
  • @Milliways I'm drawing a chart to explain the network, question updated with the command ip r – Carlo Zanocco Oct 5 at 9:43
4

The setup should not be a big problem because there are no routing requirements. The wired subnet is isolated from the wireless subnet. So you can just connect wireless to the internet router with wpa_supplicant as usual. The wired connections should work out of the box when only using static ip addresses and no name resolution. To be more comfortable you can enable a DHCP server on the wired subnet and use dDNS fore name resolution on DNS domain .local. You have only to ensure that the ip subnet on the wired subnet differs from the ip addresses on the wireless subnet.

You can find an example at How to make Raspberry Pi 4 as “WIFI” -> “Ethernet” adaptor but that works as router that we do not need. Just omit the routing and DNS stuff in /etc/systemd/network/04-eth0.network by using this file instead:

rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0

[Network]
Address=192.168.4.1/24
LLMNR=no
MulticastDNS=yes
DHCPServer=yes
EOF

If mDNS (Multicast DNS) is supported by the devices you should be able to address the RasPi from the Laptop with ping raspberrypi.local and the PLC from the RasPi with, e.g. ping plc.local. Be sure that you do not enable routing/ip forwarding on the Laptop and on the RasPi. This may confuse the network with connection loops.

| improve this answer | |
  • Just a question, if the problem is the subnet so I can solve it just changing the subnet for the network between the PLC <--> Rapberry right? Instead of 10.10.7.201/21 I can do 10.10.7.201/24. Anyway on the final release I will separate the two network to avoid any kind of problem – Carlo Zanocco Oct 5 at 11:27
  • 1
    @CarloZanocco It doesn't matter what private ip range do you use. It must only be different from the wireless ip subnet without overlapping. If this condition is given you can also use subnet 10.10.0.0/21 with 2046 ip addresses that contains 10.10.7.201/21. But subnet 10.10.7.0/24 with 254 ip addresses is also good. – Ingo Oct 5 at 12:13
  • Thank you for your help! – Carlo Zanocco Oct 5 at 12:41

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.