AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 12:28 am

Hello everyone.

Currently I'm working on home automation system powered with an RPi 3B. I have two Arduino Nano based modules, one for measuring the temperature and humidity and one to control the outputs of custom-made 3-phase electricity monitoring unit. I want Arduinos to be connected to Pi via Ethernet while the Pi itself is connected wirelessly to WiFi router and to Internet.

What I have for now: static IPs for wlan0 and eth0 are set, the data from Arduino modules is coming by request from Pi and I am able to browse Internet from inside the Pi. BUT. I cannot SSH nor ping to it from the outside (from my PC via the same WiFi router). When I disconnect the Ethernet cable from Pi I CAN SSH and ping to it.

My config files:

/etc/dhcpcd.conf

Code: Select all

# 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.
#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
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
# Some interface drivers reset when changing the MTU so disabled by default.
#option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

# Custom static IP address for eth0.
interface eth0
static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

# Custom static IP address for wlan0.
interface wlan0
static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

/etc/network/interfaces

Code: Select all

# 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

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
/etc/wpa_supplicant/wpa_supplicant.conf

Code: Select all

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

network={
    ssid="<wlan_ssid_here>"
    scan_ssid=1
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="<wlan_pwd_here>"
    id_str="Aquarius"
    priority=5
}
OS:

Code: Select all

Linux raspberrypi 4.4.34-v7+ #930 SMP Wed Nov 23 15:20:41 GMT 2016 armv7l GNU/Linux
To clarify why I need static IP on wlan0. I need to have SSH and web access to my Pi as there is running LAMP stack on it (to store and process the sensors data and show it with my CMS). The WiFi router has a bound address redirection from the outside of Internet to the Pi.

Struggling with it for the last eight days so any help is appreciated. Thanks.

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 3:07 am

Normally, the ethernet connection has the lowest metric, so it will be used as the preference. You can change that. Add the metric parameter to /etc/dhcpcd.conf. The example below will use the wlan0 interface gateway as the preference. I used my network settings here.

Code: Select all

# Custom static IP address for eth0.
interface eth0
metric 300
static ip_address=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

# Custom static IP address for wlan0.
interface wlan0
metric 200
static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
My advice applies to RaspiOS only. Please mention if you use another OS.

drgeoff
Posts: 13115
Joined: Wed Jan 25, 2012 6:39 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 10:13 am

@AlexMurphy
You have set the same IP address on the two interfaces. Change one of them to eg 192.168.0.201. Set the port forwarding to the Wi-Fi one.
Last edited by drgeoff on Tue Jan 17, 2017 10:17 am, edited 1 time in total.
Quis custodiet ipsos custodes?

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 10:15 am

Tried that. Now I'm able to SSH to Pi but Ethernet connetcion is not responding (while Networking widget on taskbar shows that is up and running).

Ping to my Arduino sensor (192.168.0.10) is not responding. Ping to router (192.168.0.1) is working. And I can use Internet from inside the Pi.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 11:39 am

Changed eth0 IP to 192.168.0.201. Now I can ping Arduino but still canot SSH to Pi from the outside and yet cannot browse Internet. Very strange...

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 12:26 pm

Did you try my example I posted above? It uses different subnets for each interface.
192.168.0.0/24 on wlan0
192.168.1.0/24 on eth0

edit: Does your router use the same subnet for both wireless and ethernet?
My advice applies to RaspiOS only. Please mention if you use another OS.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 12:49 pm

@SurferTim

My Arduino sensor is connected directly to Pi's Ethernet port, not via the router's ports.
Attachments
342587239847293874923.jpg
Network scheme
342587239847293874923.jpg (35.77 KiB) Viewed 12077 times

User avatar
RaTTuS
Posts: 10824
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 12:57 pm

AlexMurphy wrote:@SurferTim

My Arduino sensor is connected directly to Pi's Ethernet port, not via the router's ports.
you will have to make it in a different network see above
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 1:10 pm

RaTTus is correct. Use separate subnets for each interface. I use RPis with Arduinos regularly. I'm SurferTim on the Arduino forum also. My specialty there is routing and ethernet.
My advice applies to RaspiOS only. Please mention if you use another OS.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 1:14 pm

Now my dhcpcd.conf looks like this:

Code: Select all

# Custom static IP address for eth0.
interface eth0
metric 300
static ip_address=192.168.1.201/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

# Custom static IP address for wlan0.
interface wlan0
metric 200
static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
No ping/curl to Arduino (192.168.0.10), but can SSH to Pi and web server from Pi is now responding.

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 1:17 pm

That is probably due to the routing in the router. I haven't tried it yet, but I think you must route the 192.168.0.0/24 network to the RPi in the router.

edit: Did you change the Arduino to a 192.168.1.x ip address to match the eth0 interface? Here is the way you should have this set up.

Router wifi (192.168.0.1) -> RPi wifi (192.168.0.x) -> RPi -> eth0 (192.168.1.x) -> Arduino ethernet (192.168.1.y)
My advice applies to RaspiOS only. Please mention if you use another OS.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 1:38 pm

@SurferTim:

Yes, I changed Arduino's IP to 192.168.1.10. Still no luck...

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 1:46 pm

I just tried this with networks that are non-conflicting, and I can access the internet and the Arduino from my RPi. I can't access the Arduino from the internet side of the RPi because I have not set up either the routing or the masquerade in the RPi for the Arduino's subnet. Is that what you are trying?
My advice applies to RaspiOS only. Please mention if you use another OS.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 1:52 pm

I try to make Pi gather the data from Arduinos connected via Ethernet and to show this data with the web server through the WiFi. I.e. when I browse the external IP of my router it send me throug its routing rule to Raspberry Pi and shows me data from Arduino. I don't need to access Arduino directly, just from the Pi.

I need to build two networks: wired (Pi <-> Arduino) and wireless (Pi <-> router).

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 2:00 pm

That is not a problem. I just tried it, and it works fine. I have 192.168.0.0/24 on the wifi and 192.168.1.0/24 on the ethernet. What are the network settings for your wifi on the router?

edit: I presume 192.168.0.1. This will set the wifi to 192.168.0.0/24 and the Arduino to 192.168.10.0.
On the RPi

Code: Select all

# Custom static IP address for eth0.
interface eth0
static ip_address=192.168.10.200/24
static routers=192.168.10.1
static domain_name_servers=192.168.10.1

# Custom static IP address for wlan0.
interface wlan0
static ip_address=192.168.0.2/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
On the Arduino.

Code: Select all

IPAddress ip( 192,168,10,3 );
IPAddress gateway( 192,168,10,200 );
IPAddress subnet( 255,255,255,0 );
You should be able to access the Arduino from the RPi using 192.168.10.3.
My advice applies to RaspiOS only. Please mention if you use another OS.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 2:14 pm

@SurferTim:

My router has DHCP running with address range of 192.168.0.100 to 192.168.0.199. Address mask I think is 255.255.255.0 (cannot find it in router admin panel :| ).

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 2:18 pm

That is good. Use 192.168.0.200/24 for the wifi on the RPi. That is clear of your dhcp range on the router. Some routers have severe problems if you use a static ip in the dhcp range.

Use 192.168.10.200/24 for the eth0 on the RPi, and 192.168.10.3/24 on the Arduino. Are you using a w5100 ethernet shield on the Arduino? The w5200/w5500 do not have auto crossover, so they will require a ethernet crossover cable.
My advice applies to RaspiOS only. Please mention if you use another OS.

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 2:31 pm

I forgot one little '#' in that setting. Comment out the routers on the eth0 static setting.
# Custom static IP address for eth0.
interface eth0
static ip_address=192.168.10.200/24
#static routers=192.168.10.1
static domain_name_servers=192.168.10.1
My advice applies to RaspiOS only. Please mention if you use another OS.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 3:03 pm

Just tried to change dhcpcd.conf in this way:

Code: Select all

# Custom static IP address for eth0.
interface eth0
metric 300
static ip_address=192.168.10.200/24
#static routers=192.168.10.1
static domain_name_servers=192.168.10.1

# Custom static IP address for wlan0.
interface wlan0
metric 200
static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
and changed Arduino's IP to 192.168.10.10. I am able to SSH to Pi but Pi cannot get anything from Arduino. Additionally I found that eth0 interface became unstable: it re-connects randomly every 3-10 seconds :( .

I use cheap ENC28J60 Ethernet modules as I cannot find any small W5100 modules on local market. And W5100 modules are usually 2-3 times more expensive than the ENC-based ones.

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 3:16 pm

I don't use the ENC28j60, so I can't help you there.
My advice applies to RaspiOS only. Please mention if you use another OS.

AlexMurphy
Posts: 10
Joined: Mon Jan 16, 2017 7:23 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 3:48 pm

ENC28J60 works fine when I test it with Windows-based PC and connect them directly to each other. I tested it for 12 hours logging the data every 15 seconds and it was OK. So I think the problem is in Pi configuration...

I already tried to manage connections according to this: http://raspberrypi.stackexchange.com/qu ... d-ethernet

and many other how-tos. But nothing works...

drgeoff
Posts: 13115
Joined: Wed Jan 25, 2012 6:39 pm

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 4:25 pm

SurferTim wrote: The w5200/w5500 do not have auto crossover, so they will require a ethernet crossover cable.
Not correct!

The ethernet on RPis is autosensing. A crossover cable is NEVER required with a RPi.
Quis custodiet ipsos custodes?

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

Re: wlan0 and eth0 at the same time with static IPs

Tue Jan 17, 2017 5:11 pm

Yes correct, even if other device does support auto crossover.
My advice applies to RaspiOS only. Please mention if you use another OS.

tarahi
Posts: 2
Joined: Sun Mar 01, 2020 9:43 pm

Re: wlan0 and eth0 at the same time with static IPs

Fri Mar 06, 2020 9:31 am

Hi every one
My raspberry's WiFi and LAN work fine individually but not with each other !
WiFi provides VNC connection to my laptop and also Internet via hotspot.
LAN is connected to Arduino which sends the data to RBPi.
Raspbian version is buster.

/etc/network/interfaces is :

Code: Select all

# 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/dhcpd.conf is :

Code: Select all

# Custom static IP address for eth0.
interface eth0
        static ip_address=192.168.10.200/24
        static routers=192.168.10.1
        static domain_name_servers=192.168.10.1

# Custom static IP address for wlan0.
interface wlan0
        static ip_address=192.168.43.96/24
        static routers=192.168.43.1
        static domain_name_servers=192.168.43.1
Arduino IP setting is :

Code: Select all

IPAddress ip(192, 168, 10, 3);                            // Ethernet shield (W5100) IP address
IPAddress subnet(255,255,255,0 );
IPAddress mqtt_server(192, 168, 10, 200);
Whenever I connect the Ethernet cable to raspberry Pi ,my wireless connection (vnc) fails !
still connection to hotspot exists !!! But ping doesn't response !
what can be the reason ???
How can I have Both connection at the same time ???

User avatar
B.Goode
Posts: 14076
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: wlan0 and eth0 at the same time with static IPs

Fri Mar 06, 2020 10:11 am

tarahi wrote:
Fri Mar 06, 2020 9:31 am
Hi every one
My raspberry's WiFi and LAN work fine individually but not with each other !
WiFi provides VNC connection to my laptop and also Internet via hotspot.
LAN is connected to Arduino which sends the data to RBPi.
Raspbian version is buster.

/etc/network/interfaces is :

Code: Select all

# 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/dhcpd.conf is :

Code: Select all

# Custom static IP address for eth0.
interface eth0
        static ip_address=192.168.10.200/24
        static routers=192.168.10.1
        static domain_name_servers=192.168.10.1

# Custom static IP address for wlan0.
interface wlan0
        static ip_address=192.168.43.96/24
        static routers=192.168.43.1
        static domain_name_servers=192.168.43.1
Arduino IP setting is :

Code: Select all

IPAddress ip(192, 168, 10, 3);                            // Ethernet shield (W5100) IP address
IPAddress subnet(255,255,255,0 );
IPAddress mqtt_server(192, 168, 10, 200);
Whenever I connect the Ethernet cable to raspberry Pi ,my wireless connection (vnc) fails !
still connection to hotspot exists !!! But ping doesn't response !
what can be the reason ???
How can I have Both connection at the same time ???


Old question, same answer. The topic for research is Static Route.

There is a near-identical very recent thread on the same subject here: viewtopic.php?f=36&t=267161


In short, as soon as you have a system with more than one active network interface you need a routing configuration that determines which interface to use to access a particular destination. Clearly the default adopted by Raspbian Buster is not appropriate for your own requirement so needs to be customized.

Return to “Networking and servers”