ingds92
Posts: 38
Joined: Mon Mar 04, 2019 7:03 pm

Wifi for internet and Lan for plc

Mon Sep 20, 2021 8:12 pm

Hi, I'm using raspberry for modbus communication with plc and I set dhcp on wifi and static ip in another range (192.168.0.10 instead of 193.168.1.xxx of wifi) for Lan. Unfortunately internet connection break down and raspberry seems trying internet connection on Lan. Can I set to use wifi connection for internet instead of eth0 connection?

Andresayang
Posts: 46
Joined: Fri Jun 05, 2020 1:10 pm

Re: Wifi for internet and Lan for plc

Mon Sep 20, 2021 8:44 pm

ingds92 wrote:
Mon Sep 20, 2021 8:12 pm
Hi, I'm using raspberry for modbus communication with plc and I set dhcp on wifi and static ip in another range (192.168.0.10 instead of 193.168.1.xxx of wifi) for Lan. Unfortunately internet connection break down and raspberry seems trying internet connection on Lan. Can I set to use wifi connection for internet instead of eth0 connection?
Hello,

Well, The question is not very clear, so I'll summarize what I did understood:
- With you PI, you want to connect to internet using WIFI and to something else using LAN correct ?

So if it is the case, when you type in a console "ip a" you should see both interfaces.
Then enter the command:
ip route

I bet you will see both interfaces as "default", you need to delete one route (the one of your LAN) with the command:
ip route del default via "ip of your LAN interface"

This should solve your troubles. But you will have to do it each time you will boot.
I'll google to check how to do it in automatic ...

Cheers

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

Re: Wifi for internet and Lan for plc

Mon Sep 20, 2021 9:26 pm

ingds92 wrote:
Mon Sep 20, 2021 8:12 pm
Hi, I'm using raspberry for modbus communication with plc and I set dhcp on wifi and static ip in another range (192.168.0.10 instead of 193.168.1.xxx of wifi) for Lan. Unfortunately internet connection break down and raspberry seems trying internet connection on Lan. Can I set to use wifi connection for internet instead of eth0 connection?
Is this posted in the right section??

Yes you can give priority to wireless, even if both Ethernet and wireless interfaces have a default route.
On RaspiOS, edit /etc/dhcpcd.conf and add at the end of the file

Code: Select all


interface wlan0
metric 100

"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Andresayang
Posts: 46
Joined: Fri Jun 05, 2020 1:10 pm

Re: Wifi for internet and Lan for plc

Mon Sep 20, 2021 9:48 pm

epoch1970 wrote:
Mon Sep 20, 2021 9:26 pm
ingds92 wrote:
Mon Sep 20, 2021 8:12 pm
Hi, I'm using raspberry for modbus communication with plc and I set dhcp on wifi and static ip in another range (192.168.0.10 instead of 193.168.1.xxx of wifi) for Lan. Unfortunately internet connection break down and raspberry seems trying internet connection on Lan. Can I set to use wifi connection for internet instead of eth0 connection?
Is this posted in the right section??

Yes you can give priority to wireless, even if both Ethernet and wireless interfaces have a default route.
On RaspiOS, edit /etc/dhcpcd.conf and add at the end of the file

Code: Select all


interface wlan0
metric 100

Yes also ...

BeauSlim
Posts: 141
Joined: Mon Jul 31, 2017 10:02 am

Re: Wifi for internet and Lan for plc

Sun Sep 26, 2021 5:30 pm

193.x.x.x is a public, routeable block that belongs to someone.
Making up random IP addresses is a bad idea. Best case, you will have issues reaching certain sites on the net. Worst case your firewalls won't filter them.

Use addresses in these ranges for internal networks:

Code: Select all

192.168.0.0 – 192.168.255.255 
172.16.0.0 – 172.31.255.255 
10.0.0.0 – 10.255.255.255 

bls
Posts: 1755
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: Wifi for internet and Lan for plc

Sun Sep 26, 2021 7:06 pm

Andresayang wrote:
Mon Sep 20, 2021 9:48 pm
epoch1970 wrote:
Mon Sep 20, 2021 9:26 pm
ingds92 wrote:
Mon Sep 20, 2021 8:12 pm
Hi, I'm using raspberry for modbus communication with plc and I set dhcp on wifi and static ip in another range (192.168.0.10 instead of 193.168.1.xxx of wifi) for Lan. Unfortunately internet connection break down and raspberry seems trying internet connection on Lan. Can I set to use wifi connection for internet instead of eth0 connection?
Is this posted in the right section??

Yes you can give priority to wireless, even if both Ethernet and wireless interfaces have a default route.
On RaspiOS, edit /etc/dhcpcd.conf and add at the end of the file

Code: Select all


interface wlan0
metric 100

Yes also ...
And as a side note, you can disable the gateway on, for instance, eth0 in /etc/dhcpcd.conf

Code: Select all

interface eth0
    nogateway
Using nogateway prevents adding the default route for that device. dhcpcd still creates the route for the subnet on which the device is attached.

Net result: LAN traffic goes via eth0 since it has a lower metric than wifi, and off-LAN traffic routes via the wifi adapter.
Pi tools:
Quickly and easily build customized-just-for-you SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure strongSwan VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo

Return to “Networking and servers”