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