2

I have my Pi2 recently configured and run into some networking problems. When I tried setting Pi2's IP address to a static IP (192.168.1.200 in this case), upon newly starting up, it can already reach the outside network (e.g. can ping 8.8.8.8). However, Pi2 remains unreachable from other machines from within my home network, i.e. when my Pi2 address is 192.168.1.200:

$ ping 192.168.1.200

Pinging 192.168.1.200 with 32 bytes of data:
Reply from 192.168.1.111: Destination host unreachable.
Reply from 192.168.1.111: Destination host unreachable.
Reply from 192.168.1.111: Destination host unreachable.
Reply from 192.168.1.111: Destination host unreachable.

Ping statistics for 192.168.1.200:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

The weird phenomenon that I don't totally understand is, if I initiate by doing a ping from my Pi2 to my other home computer, i.e. from Pi2 do a ping 192.168.1.111, the other home computer is reachable by ping from Pi2. And then, my other home computer can reach Pi2 afterwards, with ping and ssh, etc. This is very inconvenient because I want to remotely access my Pi2 for my use, and I don't want to write a script to find out and then initiate ping to every existing IP addresses within the home address.

My home ISP router is at 192.168.1.1, here is my /etc/network/interfaces:

source-directory /etc/network/interfaces.d
## no files in the above directory

auto lo
iface lo inet loopback

allow-hotplug eth0
## eth0 not plugged in
iface eth0 inet dhcp

allow-hotplug wlan0
address 192.168.1.200
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1 8.8.8.8 8.8.4.4
wpa-ssid "MY SSID"
wpa-psk "my psk"

Here is my /etc/dhcpcd.conf:

# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# 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
####################
# EDITA IP STATICA #
####################
interface wlan0
static ip_address=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

Output from sudo 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    0      0        0 wlan0
0.0.0.0         192.168.1.1     0.0.0.0         UG    303    0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     303    0        0 wlan0

Pi2's /etc/resolv.conf:

# Generated by resolvconf
nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4

Please let me know your suggestions to find out the source of problem. Thanks in advance.

techraf
  • 4,319
  • 10
  • 31
  • 42
menuhin
  • 171
  • 1
  • 4
  • What is 192.168.1.111? What is its routing configuration? How are "other machines from within my home network" configured? – techraf Feb 15 '16 at 13:32
  • 1
    As I always advise: never set a static IP in a machine, do it via your DHCP (router). – Havnar Feb 15 '16 at 14:19
  • @Havnar that's a good advice, but sadly there are people out there who don't have permissions to configure their routers (including myself). – scherzkrapferl Feb 15 '16 at 14:42
  • If the router you refer to is an ISP router, I also advise against using that one ;) – Havnar Feb 15 '16 at 15:11
  • @techraf 192.168.1.111 is just another computer in the same network, it's routing configuration is using 192.168.1.1 as the gateway and DHCP. – menuhin Feb 15 '16 at 16:31
  • @Havnar, I initially wanted to use DHCP, following exactly as stated in some tutorials (http://raspberrypi.stackexchange.com/questions/42637/dhcp-failed-on-wlan0-keep-getting-169-254-x-x-addresses?noredirect=1#comment61938_42637) but that gave me some weird IP addresses and zero connectivity to the internet. With static IP, at least I have connected to the Internet and then did some apt-get update / upgrade. – menuhin Feb 15 '16 at 16:39
  • If your dhcp server did not provide the ip you set, it might cause issues, even more so if you get an ip conflict. Set your static IP outside of the dhcp range but within the subnet range – Havnar Feb 15 '16 at 22:11
  • Well, if you won't provide information, you won't get an answer. "just another computer" does not provide any details. – techraf Feb 15 '16 at 22:35
  • @techraf here are the details:

    Connection-specific DNS Suffix . : localdomain Link-local IPv6 Address . . . . . : fe80::b156:405e:5f30:c9f7%2 IPv4 Address. . . . . . . . . . . : 192.168.1.111 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1

    They share the same router and subnet mask.

    – menuhin Feb 15 '16 at 23:50
  • Pi is probably not yet involved and the error reason is limited 111 machine. What happens if you ping other (non-existent) addresses? Do you get a timeout or destination host unavailable? – techraf Feb 16 '16 at 00:31
  • @techraf I'm getting a "Destination host unreachable" when I ping non-existent addresses. – menuhin Feb 16 '16 at 00:37
  • The problem seems to be on 111 machine not 200. – techraf Feb 16 '16 at 00:53

2 Answers2

1

Check out the ARP tables on all devices. If a device receives an address from DHCP it can change when the lease expires. However, all devices on the network are not notified about the new address, so they may have an IP address associated with the old user of the address, sometimes for hours. When you ping from the Pi that causes the other device to learn the new MAC address for an IP address.

To fix, use static addresses for everything. Or, use persistent DHCP addresses (a/k/a reservations) (what I do): everything still uses DHCP but they always get the same address. The exact way to do this differs based on router manufacturer.

dk1
  • 111
  • 2
  • " ... However, all devices on the network are not notified about the new address, so they may have an IP address associated with the old user of the address, sometimes for hours. When you ping from the Pi that causes the other device to learn the new MAC address for an IP address. ..." --- this is what I have been thinking and I am not from any networking background and do not know how machines in the same network can be notified about all the newly set static IP addresses. Thanks for your help. – menuhin Feb 16 '16 at 09:54
1

So I thought I found the root cause of this problem:

The WiFi USB dongle was not fully supported: it has a Realtek RTL8191S WLAN chipset and although it was fully recognized and even the static IP somewhat worked (after initiating a ping as described above), DHCP was not fully supported anyways. Some other people ran into similar problems with the same dongle: http://www.forum-raspberrypi.de/Thread-csl-wlan-usb-stick-funktioniert-nicht

I did an rpi-update to update the firmware and then after reboot, the same static IP setting was all working fine. And I can ping / ssh from the 192.168.1.111 and other machines within the local network without having to do any ping from the Pi2 first.

However, after I did some other software package installation and updates (apache2, php5, MySQL, texlive, gimp, emacs, and some user USB drive mount-unmount scripts), the problem reappeared again. :\

menuhin
  • 171
  • 1
  • 4