2

On a Raspberry Pi 3B+ I want to have a all the functionality services (ssh, vnc, dhcp) on a wired intranet on eth0 and the Internet wirelessly on wlan0. I have installed the servers and under some circumstances I can connect from a Laptop (Windows 10) to the Raspberry Pi via ethernet, get an IP and access using putty, WinSCP and VNC Viewer.

However, I have a few problems for which I would like some help.

  1. When I define an static IP for eth0 (Editing /etc/network/interfaces) then the wifi stops working.
  2. Connection drops after some time, inexplicably to me.
  3. Sometimes Windows will get an IP outside the DHCP allocated range (i.e 169.254.96.197)

My questions:

  1. Why adding a static IP for eth0 in /etc/network/interfaces breaks wifi?
  2. What could be causing the connection to break?
  3. Why does windows sometimes not get the IP from the DHCP server? (And how to fix it)

Below some relevant information:

Linux raspberrypi 4.19.97-v7+ #1294 SMP

Without static IP odefinition in /etc/network/interfaces wifi working

With static IP odefinition in /etc/network/interfaces Wifi not working

Network failing halfway file transfer enter image description here

Physical connections:

Laptop : Gigabit USB3 Ethernet adapter 
Cat5E Ethernet cable
D-Link DES-108
Cat5E Ethernet cable
Raspberry Pi 3B+

Installation procedure

apt-get update
raspi-config % For ssh and VNC access
apt-get install isc-dhcp-server

sudo service isc-dhcp-server stop
ifconfig eth0 down

dpkg-reconfigure  isc-dhcp-server
nano /etc/default/isc-dhcp-server
nano /etc/dhcp/dhcpd.conf
nano /etc/network/interfaces

ifconfig eth0 up
service isc-dhcp-server start

File /etc/default/isc-dhcp-server contains

INTERFACESv4="eth0"
INTERFACESv6=""

File /etc/network/interfaces contains

# Static IP for intranet DHCP server
auto eth0
iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    broadcast 192.168.1.255

File dhcpd.conf contains

# option definitions common to all supported networks...
option domain-name "internal.mydomain.com";
option domain-name-servers 1.1.1.1, 8.8.8.8;

default-lease-time 600;
max-lease-time 7200;

ddns-update-style none;

# Subnet declaration.

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.1 192.168.1.250;
  option domain-name "internal.mydomain.com";
  option broadcast-address 192.168.1.255;

EDIT

I have followed @M._Rostami's advice and installed dnsmasq.conf . The wifi problem is gone, but still have the problem of been disconnected after some time (or amount of network activity? it seems to correlate with that.) If I disconnect/connect the USB network adapter on the windows laptop side the communication is restored.

WIndows PC routing table

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0   10.100.100.254   10.100.100.112     25
          0.0.0.0          0.0.0.0      192.168.1.1    192.168.1.113     35
     10.100.100.0    255.255.255.0         On-link    10.100.100.112    281
   10.100.100.112  255.255.255.255         On-link    10.100.100.112    281
   10.100.100.255  255.255.255.255         On-link    10.100.100.112    281
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
      192.168.1.0    255.255.255.0         On-link     192.168.1.113    291
    192.168.1.113  255.255.255.255         On-link     192.168.1.113    291
    192.168.1.255  255.255.255.255         On-link     192.168.1.113    291
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link    10.100.100.112    281
        224.0.0.0        240.0.0.0         On-link     192.168.1.113    291
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
  255.255.255.255  255.255.255.255         On-link    10.100.100.112    281
  255.255.255.255  255.255.255.255         On-link     192.168.1.113    291
===========================================================================

Raspberry pi route

pi@raspberrypi:~ $ route -v
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.128.128.128  0.0.0.0         UG    303    0        0 wlan0
10.0.0.0        0.0.0.0         255.0.0.0       U     303    0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0

EDIT2

I have tried disabling all other network adaptors both in window side and on Raspberry Pi side. I can consistently make the network to fail (ping will stop, ssh would fail, etc..) by transferring a large file with WinSCP. Connection recovers if I unplug/plug the USB adaptor on the windows side.

rhermans
  • 129
  • 5
  • As your edit, please add all previous in this new case. We need to know what you have done after that. I mean add the output of cat etc/network/interfaces, cat /etc/dhcpcd.conf, cat /etc/dnsmasq.conf and ifconfig. – M. Rostami Feb 21 '20 at 16:21
  • I'd add as a comment to the other answer(s) but can't due to 'reputation' limitations. It sounds like a default route problem. Do a 'route' command before and after you experience this problem. When you lose Internet, you may find that your 'default route' is pointing at your internal network, not the Internet on your externally facing interface. Note that DHCP normally provides a default gateway, which may not be what you desire. – dave58 Feb 20 '20 at 06:24

2 Answers2

2

Connection drops after some time, inexplicably to me.

It has happened because of your configuration since the network manager has changed on newer Raspbian. Please add the static IP according to the /etc/dhcpcd.conf for the eth0.

Leave the /etc/network/interfaces with:

# 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

Change the configuration:

sudo nano /etc/dhcpcd.conf

Change these lines as you want:

# static IP configuration:
interface eth0
static ip_address=192.168.1.1/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static domain_name=internal.mydomain.com

Sometimes Windows will get an IP outside the DHCP allocated range (i.e 169.254.96.197)

The isc-dhcp-server can be the problem. Check the /var/log/syslog to understand what's happening with DHCP request/response and the service.

However, dnsmasq is better if you want to configure a DHCP server. Install it simply by the following procedure.

sudo apt-get install dnsmasq  

sudo nano /etc/dnsmasq.conf  

Add these lines:

interface=eth
listen-address=192.168.1.1
bind-interfaces 
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.1.100,192.168.1.200,2h  

Network failing halfway file transfer

The IP conflict can be the problem. Maybe you have another 192.168.1.1 on your network because it's the common factory IP address for a consumer-grade router which you may be connected by wlan0.

M. Rostami
  • 4,323
  • 1
  • 17
  • 36
1

You have not specified OS - I assume some version of Raspbian.

When I define an static IP for eth0 (Editing /etc/network/interfaces) then the wifi stops working

This is normal behaviour for Debian networking and as you have only listed part of your /etc/network/interfaces who knows exactly.
I could elaborate, but as this is effectively obsolete suggest you do it the Raspbian way.

Is there any reason you ignored the warning in /etc/network/interfaces?

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

If you really must use static IP do it properly see How to set up Static IP Address

To setup networking properly see How to set up networking/WiFi Although to perform your unusual setup this requires a bit of configuration.

You do not appear to want to setup an Access Point but you could modify the settings to use eth0 as a DHCP server for your local network. NOTE attempting to use 2 DHCP servers on the same network is impossible.

You appear to have modified lots of files which are not used in normal Raspbian networking

Sometimes Windows will get an IP outside the DHCP allocated range (i.e 169.254.96.197)

This is a Link-local address and indicates no IP has been allocated.

Milliways
  • 59,890
  • 31
  • 101
  • 209