ebility
Posts: 4
Joined: Wed Oct 24, 2018 10:07 am

Simultaneous access ethernet and wifi

Wed Oct 24, 2018 10:47 am

Hello.. :)

I have a raspberry pi 2 model B. I have configured the pi with latest OS (raspbian stretch) and enabled XRDP in order to access it via remote desktop. I have also configured static IP address to my RPI (192.168.1.10). I connect the RPI directly to my laptop via an Ethernet cable and access it via "Remote desktop connection".Following lines are there in dhcpcd.conf file

Code: Select all

 interface eth0
                    static ip_address=192.168.1.10/24
                     static routers=192.168.1.1
                     static domain_name_servers=192.168.1.1

Everything is working fine till this step.

Now, I have added a Wifi USB dongle (EDIMAX: https://www.amazon.de/EDIMAX-EW-7811UN- ... B003MTTJOY) and changed the dhcpcd.conf file as follows:

Code: Select all

interface eth0
static ip_address=192.168.1.10/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface wlan0
allow-hotplug wlan0
I have also updated the /etc/wpa_supplicant/wpa_supplicant.conf and entered correct parameters

Code: Select all

network={
        ssid="MGM"
        psk="xxxxxxxx"
        key_mgmt=WPA-PSK
}
The problem is, I can not use both the interfaces simultaneously. My requirement is, I should be able to connect to Pi via Ethernet cable and at the same time, I should remain connected with the WiFi to access internet through browser. When I disconnect the Ethernet cable and connect my laptop to same wifi router (to which RPi is also connected) then I can access the RPi through the dynamic IP address given by Wifi router to Pi. But both the interfaces (eth0 and wlan0) are not working simultaneously. After accessing the Pi via remote desktop, it shows that, it is connected to wifi as shown in the following image..
RDC.png
RDC.png (25.8 KiB) Viewed 17835 times
I also inserted metric <priority> for priorities but it didn't work.
An expert advice would be really appreciated..
Thanks :)

SurferTim
Posts: 2054
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Simultaneous access ethernet and wifi

Wed Oct 24, 2018 11:42 am

The RPi is having routing problems due to the same localnet on both interfaces.

You have a choice.
1) Change the localnet on one of the interfaces.
or
2) Use routing marks to determine the routes.

#1 is by far the simplest solution.
My advice applies to RaspiOS only. Please mention if you use another OS.

klricks
Posts: 8805
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA

Re: Simultaneous access ethernet and wifi

Wed Oct 24, 2018 12:23 pm

IMO the simplest solution is to use DHCP IP to MAC reservations in the router instead of static config on the RPi.
Leave the RPi set to default DHCP setup.
On the router assign one IP to the MAC address of the Ethernet and assign a different IP to the MAC of the WIFI.
This method just works with no config changes on the RPi.
Unless specified otherwise my response is based on the latest and fully updated RPi OS Bullseye w/ Desktop OS.

SurferTim
Posts: 2054
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Simultaneous access ethernet and wifi

Wed Oct 24, 2018 12:32 pm

klricks wrote: IMO the simplest solution is to use DHCP IP to MAC reservations in the router instead of static config on the RPi.
Leave the RPi set to default DHCP setup.
On the router assign one IP to the MAC address of the Ethernet and assign a different IP to the MAC of the WIFI.
This method just works with no config changes on the RPi.
If both interfaces are issued the same localnet by a DHCP server, how will that resolve the routing problem?
My advice applies to RaspiOS only. Please mention if you use another OS.

klricks
Posts: 8805
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA

Re: Simultaneous access ethernet and wifi

Wed Oct 24, 2018 1:19 pm

SurferTim wrote:
Wed Oct 24, 2018 12:32 pm
klricks wrote: IMO the simplest solution is to use DHCP IP to MAC reservations in the router instead of static config on the RPi.
Leave the RPi set to default DHCP setup.
On the router assign one IP to the MAC address of the Ethernet and assign a different IP to the MAC of the WIFI.
This method just works with no config changes on the RPi.
If both interfaces are issued the same localnet by a DHCP server, how will that resolve the routing problem?
I am not sure what the problem is? I don't have any problem using 2 interfaces at the same time. I can open 2 ssh sessions one on WIFI and one on Ethernt or ssh on one and VNC on the other no problem. Note I logon to each using the assigned IP addresses.
Unless specified otherwise my response is based on the latest and fully updated RPi OS Bullseye w/ Desktop OS.

SurferTim
Posts: 2054
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Simultaneous access ethernet and wifi

Wed Oct 24, 2018 1:39 pm

I can also, as long as the subnets are different. Are your wlan0 and eth0 subnets identical?
My advice applies to RaspiOS only. Please mention if you use another OS.

Ernst
Posts: 1386
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Simultaneous access ethernet and wifi

Wed Oct 24, 2018 2:02 pm

The most usable configuration in this case is to use WiFi only, do not configure or connect ethernet.
Multiple interfaces within the same subnet or in different subnets is not easy because of routing, it works under some conditions, it may seem to work under certain conditions, or it does not work at all.

It is very important to understand a little bit about routing how a packet moves from one system to the next system, with every transition the local routing table is used to decide which interface will be used to transmit the message and to which mac address. If both interfaces are within the same subnet the routing metric is used to determine which interface will be used, which is normally the ethernet interface. Addressing the system from the outside can be done by using the ip address assigned to the interface. An ssh connection using the ip address on the WiFi interface will be received, but the answer comes from inside and the routing table is used to decide the outgoing interface which will be the ethernet port.

The "simple" solution might be to let dhcp do the work, WiFi will get the configuration from dhcp but ethernet, connected to your PC, fails and selects a local 169.254.x.x address, the same should happen on your PC. Once done you must find what address has been taken on the ethernet interface and then you will be able to use ssh to access the Pi. I do not have any resources to test at the moment but I do suspect that it should be possible to configure a 169.254.x.x fallback address (without gateway) on the Pi ethernet interface that can then be used on the PC for ssh access. The logic is that the PC routes to the Pi using the 169.254.x.x/16 address on the local ethernet interface connected to 169.254.x.x/16 subnet, the Pi does the same for the return traffic. Any other IP address not within the same subnet as the interface(s) is routed to the default gateway (which must be within the subnet as the interface).
The road to insanity is paved with static ip addresses

epoch1970
Posts: 8445
Joined: Thu May 05, 2016 9:33 am
Location: France

Re: Simultaneous access ethernet and wifi

Wed Oct 24, 2018 3:46 pm

https://lb.raspberrypi.org/forums/viewt ... p?t=140252
I suggest the 3rd code block, ie

Code: Select all

######################################################
# TEMPLATE: A static IP address only when no DHCP
#
#           The profile name is arbitrary. Use "fred"
#           if you want. Not much we can put as
#           default servers, but set them up as
#           you usually would.
######################################################
interface eth0
fallback nodhcp

profile nodhcp
static ip_address=10.0.0.1/8
static routers=10.0.0.1
static domain_name_servers=10.0.0.1
Use an address like 10.0.0.2 (netmask 255.0.0.0) on your PC for direct connection.
When you plug the Pi's ethernet back on the main network it will acquire a DHCP address on 192.168.1.0

You can't use the same network on 2 interfaces without getting into issues. Metric routes all traffic via the preferred interface; one interface sits there doing nothing. If you setup "advanced routing" you can have traffic routed back by the receiving interface. But I have no idea how dhcpcd or the desktop network manager would react.
Just use 2 networks.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

ebility
Posts: 4
Joined: Wed Oct 24, 2018 10:07 am

Re: Simultaneous access ethernet and wifi

Thu Oct 25, 2018 1:58 pm

SurferTim wrote:
Wed Oct 24, 2018 1:39 pm
I can also, as long as the subnets are different. Are your wlan0 and eth0 subnets identical?
Yes. Both the subnets are 255.255.255.0
But both the networks are also different. (WLAN0 is connected to router and ETH0 is connected to laptop. The thing is, I use "Codesys control for raspberry PI" utility to control the motors via Modbus-TCP through Ethernet port. So, I need to put IP address of ETH0 as 192.168.1.10 in any case. (The utility enables modbus TCP via Ethernet port of RPi)
I want to access internet via WLAN0 without disturbing ETH0. So far, the motors are running absolutely fine via modbus-TCP through Ethernet. I just want to add wlan0 which will be connected to internet to access the webpages.

ebility
Posts: 4
Joined: Wed Oct 24, 2018 10:07 am

Re: Simultaneous access ethernet and wifi

Thu Oct 25, 2018 2:02 pm

Ernst wrote:
Wed Oct 24, 2018 2:02 pm
The most usable configuration in this case is to use WiFi only, do not configure or connect ethernet.
Multiple interfaces within the same subnet or in different subnets is not easy because of routing, it works under some conditions, it may seem to work under certain conditions, or it does not work at all.

It is very important to understand a little bit about routing how a packet moves from one system to the next system, with every transition the local routing table is used to decide which interface will be used to transmit the message and to which mac address. If both interfaces are within the same subnet the routing metric is used to determine which interface will be used, which is normally the ethernet interface. Addressing the system from the outside can be done by using the ip address assigned to the interface. An ssh connection using the ip address on the WiFi interface will be received, but the answer comes from inside and the routing table is used to decide the outgoing interface which will be the ethernet port.

The "simple" solution might be to let dhcp do the work, WiFi will get the configuration from dhcp but ethernet, connected to your PC, fails and selects a local 169.254.x.x address, the same should happen on your PC. Once done you must find what address has been taken on the ethernet interface and then you will be able to use ssh to access the Pi. I do not have any resources to test at the moment but I do suspect that it should be possible to configure a 169.254.x.x fallback address (without gateway) on the Pi ethernet interface that can then be used on the PC for ssh access. The logic is that the PC routes to the Pi using the 169.254.x.x/16 address on the local ethernet interface connected to 169.254.x.x/16 subnet, the Pi does the same for the return traffic. Any other IP address not within the same subnet as the interface(s) is routed to the default gateway (which must be within the subnet as the interface).
I need to use both the interfaces simultaneously in any case.
I use "Codesys control for raspberry PI" utility to control the motors via Modbus-TCP through Ethernet port. So, I can't disable ETH0.
I want to access internet via WLAN0 without disturbing ETH0. I just want to add wlan0 which will be connected to internet to access the webpages. Both the interfaces will have different network.

Ernst
Posts: 1386
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Simultaneous access ethernet and wifi

Thu Oct 25, 2018 8:47 pm

ebility wrote:
Thu Oct 25, 2018 1:58 pm
SurferTim wrote:
Wed Oct 24, 2018 1:39 pm
I can also, as long as the subnets are different. Are your wlan0 and eth0 subnets identical?
Yes. Both the subnets are 255.255.255.0
But both the networks are also different. (WLAN0 is connected to router and ETH0 is connected to laptop. The thing is, I use "Codesys control for raspberry PI" utility to control the motors via Modbus-TCP through Ethernet port. So, I need to put IP address of ETH0 as 192.168.1.10 in any case. (The utility enables modbus TCP via Ethernet port of RPi)
I want to access internet via WLAN0 without disturbing ETH0. So far, the motors are running absolutely fine via modbus-TCP through Ethernet. I just want to add wlan0 which will be connected to internet to access the webpages.
You have a misunderstanding about the meaning of networks.
Network, or subnet, is a combination of a network address combined with a network mask.
The network mask, either using xxx.xxx.xxx.xxx notation or /xxx, indicates which bits in the address will be used to determine the network. The network mask originally depends on the IP network class, class A uses 255.0.0.0 or /8, class B uses 255.255.0.0 or /16, class C uses 255.255.255.0 or /24. https://www.computerhope.com/jargon/i/ip.htm
192.168.0.x is a private class C address range (https://en.wikipedia.org/wiki/Private_network) with the subnet mask 255.255.255.0 or /24.

What this means is that the IP addresses assigned to eth0 (192.168.1.10/24) and wlan0 (192.168.1.229) are in the same network because /24 = 255.255.255.0 applied to IP address gives network 192.168.1.0, which means that only one gateway (=router) can be defined within this network for both interfaces, what interface will be used depends on the "default" gateway and the metric assigned to the interfaces. What happens is that the destination address (of a packet) is used to determine the route to be used, if the destination address is in the same subnet as one of the interfaces then the packet will be send via this interface to the destination but if there is no matching subnet then the packet is send to the default gateway.

IIRC I already suggested to use 169.254.x.x (ip4 link local addresses) on the Pi for the ethernet connection, a quick test gives the impression that dhcpcd does not allow this. You can assign a fixed 192.168.2.0/24 address, without giving a router and dns address, to eth0 and the ethernet interface on your PC. When you now use ssh to connect to the Pi the packets will be send directly on the PC network interface because both addresses are on the same network and the Pi will reply on the eth0 interface. At the same time an address in the 192.168.1.x network can be assigned to Wlan0 (using dhcp or fixed) with a router address in the same network to provide access to the rest of the world from the Pi. (Note: If the PC has two ethernet interfaces then one interface can have an address in the 192.168.1.x network to access the internet)

/etc/dhcpcd.conf:

Code: Select all

# Example static IP configuration:
interface eth0
static ip_address=192.168.2.100/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.2.1
#static domain_name_servers=192.168.2.1 8.8.8.8 fd51:42f8:caae:d92e::1

Code: Select all

pi@raspi8:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.1.255
        ether b8:27:eb:79:91:3f  txqueuelen 1000  (Ethernet)
        RX packets 112  bytes 8593 (8.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 1530 (1.4 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
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 16  bytes 1618 (1.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1618 (1.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.173  netmask 255.255.255.0  broadcast 192.168.0.255
        ether b8:27:eb:2c:c4:6a  txqueuelen 1000  (Ethernet)
        RX packets 270  bytes 24718 (24.1 KiB)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 210  bytes 31781 (31.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Code: Select all

pi@raspi8:~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.0.254   0.0.0.0         UG    303    0        0 wlan0
192.168.0.0     0.0.0.0         255.255.255.0   U     303    0        0 wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0
The road to insanity is paved with static ip addresses

ebility
Posts: 4
Joined: Wed Oct 24, 2018 10:07 am

Re: Simultaneous access ethernet and wifi

Fri Oct 26, 2018 1:09 pm

Ernst wrote:
Thu Oct 25, 2018 8:47 pm
ebility wrote:
Thu Oct 25, 2018 1:58 pm
SurferTim wrote:
Wed Oct 24, 2018 1:39 pm
I can also, as long as the subnets are different. Are your wlan0 and eth0 subnets identical?
Yes. Both the subnets are 255.255.255.0
But both the networks are also different. (WLAN0 is connected to router and ETH0 is connected to laptop. The thing is, I use "Codesys control for raspberry PI" utility to control the motors via Modbus-TCP through Ethernet port. So, I need to put IP address of ETH0 as 192.168.1.10 in any case. (The utility enables modbus TCP via Ethernet port of RPi)
I want to access internet via WLAN0 without disturbing ETH0. So far, the motors are running absolutely fine via modbus-TCP through Ethernet. I just want to add wlan0 which will be connected to internet to access the webpages.
You have a misunderstanding about the meaning of networks.
Network, or subnet, is a combination of a network address combined with a network mask.
The network mask, either using xxx.xxx.xxx.xxx notation or /xxx, indicates which bits in the address will be used to determine the network. The network mask originally depends on the IP network class, class A uses 255.0.0.0 or /8, class B uses 255.255.0.0 or /16, class C uses 255.255.255.0 or /24. https://www.computerhope.com/jargon/i/ip.htm
192.168.0.x is a private class C address range (https://en.wikipedia.org/wiki/Private_network) with the subnet mask 255.255.255.0 or /24.

What this means is that the IP addresses assigned to eth0 (192.168.1.10/24) and wlan0 (192.168.1.229) are in the same network because /24 = 255.255.255.0 applied to IP address gives network 192.168.1.0, which means that only one gateway (=router) can be defined within this network for both interfaces, what interface will be used depends on the "default" gateway and the metric assigned to the interfaces. What happens is that the destination address (of a packet) is used to determine the route to be used, if the destination address is in the same subnet as one of the interfaces then the packet will be send via this interface to the destination but if there is no matching subnet then the packet is send to the default gateway.

IIRC I already suggested to use 169.254.x.x (ip4 link local addresses) on the Pi for the ethernet connection, a quick test gives the impression that dhcpcd does not allow this. You can assign a fixed 192.168.2.0/24 address, without giving a router and dns address, to eth0 and the ethernet interface on your PC. When you now use ssh to connect to the Pi the packets will be send directly on the PC network interface because both addresses are on the same network and the Pi will reply on the eth0 interface. At the same time an address in the 192.168.1.x network can be assigned to Wlan0 (using dhcp or fixed) with a router address in the same network to provide access to the rest of the world from the Pi. (Note: If the PC has two ethernet interfaces then one interface can have an address in the 192.168.1.x network to access the internet)

/etc/dhcpcd.conf:

Code: Select all

# Example static IP configuration:
interface eth0
static ip_address=192.168.2.100/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.2.1
#static domain_name_servers=192.168.2.1 8.8.8.8 fd51:42f8:caae:d92e::1

Code: Select all

pi@raspi8:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.1.255
        ether b8:27:eb:79:91:3f  txqueuelen 1000  (Ethernet)
        RX packets 112  bytes 8593 (8.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 1530 (1.4 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
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 16  bytes 1618 (1.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1618 (1.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.173  netmask 255.255.255.0  broadcast 192.168.0.255
        ether b8:27:eb:2c:c4:6a  txqueuelen 1000  (Ethernet)
        RX packets 270  bytes 24718 (24.1 KiB)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 210  bytes 31781 (31.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Code: Select all

pi@raspi8:~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.0.254   0.0.0.0         UG    303    0        0 wlan0
192.168.0.0     0.0.0.0         255.255.255.0   U     303    0        0 wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0
Thanks a lot Ernst...
I have changed ip address of eth0 as 192.168.10.10/24 and changed the dhcpcd.conf file as mentioned by you and it is working now. :)
Thanks a lot for explanation as well as it cleared my misunderstanding about the subnet.. :) I can access internet via wlan and I can also use the Ethernet port..

Return to “Troubleshooting”