2

I am currently working on Raspberry Pi 3B+ (Stretch 9) and I have been stumped on how to be connected online wirelessly while also having my LAN port configured to receive and send data via a crossover Ethernet cable to an external piece of hardware (Note: the hardware via the LAN port is being interrogated with a Java program and does not need a bridged connection). The hardware defaults to the following settings:

IP Address: 192.168.1.100
Subnet Mask: 255.255.255.0
Gateway: 192.168.1.1

I can make the hardware work by the edit shown below but it disables my wireless connection.

Editing the /etc/dhcpcd.conf with:

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

If this might be any help hardware works but disconnected wirelessly from the internet, here is the output of route -n:

Kernel IP routing table
        Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
        0.0.0.0         192.168.1.1     0.0.0.0         UG    202    0        0 eth0
        0.0.0.0         192.168.1.8     0.0.0.0         UG    303    0        0 wlan0
        192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0
        192.168.1.0     0.0.0.0         255.255.255.0   U     303    0        0 wlan0

Edit: When disconnecting the Ethernet cable the wifi works again. As far as I can tell it is due to the default route of the Ethernet (thanks softweyr), however I am still unsure as to how to solve this. In "route -v" it shows:

Kernel IP routing table
        Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
        default         192.168.1.1     0.0.0.0         UG    202    0        0 eth0
        default         192.168.1.8     0.0.0.0         UG    303    0        0 wlan0
        192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0
        192.168.1.0     0.0.0.0         255.255.255.0   U     303    0        0 wlan0

Final Solution: I changed the hardware interface connection to 192.168.2.255 so that eth0 and wlan0 would not be in the same subnet (thanks Ingo) and changed as follows: /etc/dhcpcd.conf

interface wlan0
static ip_address=undefined/24
static routers=undefined
static domain_name_servers=undefined 8.8.8.8



interface eth0
static ip_address=192.168.2.200/24
static domain_name_servers=192.168.2.0
3
  • It could be routing, please post info about IP on WiFi network and the output from route print.
    – MatsK
    Commented Feb 4, 2019 at 19:30
  • Possible duplicate of Setting up a Raspberry Pi as an access point - the easy way
    – Ingo
    Commented Feb 4, 2019 at 19:45
  • 1
    You updated you question by setting static domain_name_servers=192.168.2.0 in /etc/dhcpcd.conf. Please don't use this address as single ip address for e.g. a nameserver. It is not a single ip address and you cannot reach a network device with it. This address stands for the whole subnet 192.168.2.0/24 (single addresses 192.168.2.1 - 192.168.2.254, 192.168.2.255 is the broadcast address).
    – Ingo
    Commented Feb 12, 2019 at 10:36

2 Answers 2

3

As you already have found, the problem is default routing. You have two default routes:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    202    0        0 eth0
default         192.168.1.8     0.0.0.0         UG    303    0        0 wlan0

If the kernel does not know where to send packages it sends it to the gateway on the default route. Because it can only use one default route it has to decide what route to use. For this it uses the Metric. The route with the lowest Metric is used, so it will send unknown packages to gateway 192.168.1.1 if the ethernet cable is plugged in. If you pull it out then the kernel uses the next available default route on interface wlan0 and sends unknown packages to gateway 192.168.1.8.

Obviously only gateway 192.168.1.8 has a connection to the internet. I don't know for what do you need gateway 192.168.1.1 but it does not connect to the internet. So the first step is to avoid declaring it as gateway. Just delete the line static routers=192.168.1.1 in /etc/dhcpcd.conf. If you need to send data to a specific network behind gateway 192.168.1.1 you have to define a static route on the RasPi.

There is another issue. You connect two interfaces eth0 and wlan0 to the same subnet 192.168.1.0. The kernel can also use only one interface and decides it also using the Metric. If you want to use both interfaces at the same time and not using a bridge you have to use different subnets behind each interface, for example 192.168.1.0/24 for eth0 and 192.168.2.0/24 for wlan0. If you want a connection between the subnets then you have to use routing and enable ip forwarding.

1

Don't accept a default route on the Ethernet network. As long as the default route you get from the WiFi network remains the only default route, your Pi will route everything to the IP network for the Ethernet to the Ethernet interface, and everything else with go to the WiFi interface.

You can do this on Raspbian with the following stanza in /etc/dhcpcd.conf:

interface eth0
  no gateway

Note that this is dhcpcd configuration, the "client daemon".

How this works:

You have made your Pi a "dual homed host" now. When the IP network comes up, three entries are added to the IPv4 routing table:

  • A route to the IP network the Ethernet is on, for instance 192.168.42.0, via the Ethernet interface.
  • A route to the IP network the WiFi is on, for instance 192.168.1.0, via the WiFi interface.
  • A default route, that is used when no more specific route matches.

Routes are matched in most specific to least specific order. If you send a packet to an address in the 192.168.42.1-254 range, or to the 192.168.42.255 broadcast address, it will go out the Ethernet interface; similarly for packets addressed to the 192.168.1.0 network and the WiFi interface. If you send a packet to an address not on either of these networks, the only route that matches is the default route, so the your TCP/IP stack will send it to the router via the WiFi interface.

You enabled this by not accepting a default route on the Ethernet, since that isn't connected to the Internet. Another solution would be to configure the DHCP server on that network to not give out default routes, since it isn't truly a gateway device.

Why it isn't going to work for you: your edit to the question clarified the problem significantly. You cannot have the WiFi and Ethernet networks both be the same network address -- 192.168.1.0 -- and have a host be able to talk to both. Hosts can talk to two networks, but they have to be two network addresses. You're going to have to "Re-IP" one of the networks, either the WiFi or the Ethernet.

1
  • Can you expand on this on how this keeps my connection to the internet via wireless while also keeping the IP address and LAN port to accept the hardware I have via the Ethernet cable? I tried your suggestion as well as different variations to no avail. I will update my post with more details. Commented Feb 6, 2019 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.