hiiragizawa
Posts: 4
Joined: Thu Aug 27, 2015 8:08 am

[SOLVED] Able to SSH via public IP but not local IP

Thu Aug 27, 2015 8:37 am

Hi all,

I have an issue which may not be of high priority as there is obviously a workaround but something which may be a potential bug that I could log. I've search for similar topics but I have not found a similar one so I'm creating a new post.

Background: SSH into Pi 2 with Raspbian v4.1.6-v7+ #810. Pi only has WiFi with chipset 8188EU connected via USB and some GPIO pins connected. Pi has a power supply of 5V 2A.

Issue: Able to successfully SSH via public IP address where the router is port forwarded to a static local IP address.
However, fail to SSH via local IP address when in LAN.

Interesting observations:
1. This occurs randomly but usually during the evening.
2. Sometimes, the local IP address may be resolved on it's own after multiple tries and I could ping/SSH locally, otherwise the Pi needs to be restarted. During the multiple tries, Pi becomes slow. I have Apache running and sometimes I am not able to load the website hosted/website takes too long to load.
3. The router R/ARP table sometimes do not contain the static IP address configured in Pi. When it doesn't, I am still able to log in via SSH through public IP address.
4. When SSH via public IP, a ping to the router (192.168.1.1) or any other hosts gives time outs.
5. wlan0 has 2 IP addresses - one DHCP and one static. [Edit 29 August 2015: Only has one IP now after reconfig]

Hypothesis of root cause of issue:
It may be due to the WiFi chipset (I've been a stingy bastard - 3 AUD on eBay) due to high drop rates in wlan0.
I plan to buy a new WiFi USB (any cheap recommendations) to just test it put, but before I do, I wanted to see what else I can do based on your suggestions first to solve this issue.

Any help appreciated.

Cheers!

Logs:

When logged in via public IP address:
pi@raspberrypi ~ $ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether b8:27:eb:2c:67:7c brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:0b:81:9b:9e:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.1.52/24 brd 192.168.1.255 scope global wlan0
valid_lft forever preferred_lft forever
inet 192.168.1.15/24 brd 192.168.1.255 scope global secondary wlan0
valid_lft forever preferred_lft forever
pi@raspberrypi ~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:2c:67:7c
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:58 errors:0 dropped:0 overruns:0 frame:0
TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5264 (5.1 KiB) TX bytes:5264 (5.1 KiB)

wlan0 Link encap:Ethernet HWaddr 00:0b:81:9b:9e:ce
inet addr:192.168.1.52 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:54652 errors:0 dropped:3031 overruns:0 frame:0
TX packets:27384 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7599662 (7.2 MiB) TX bytes:12225250 (11.6 MiB)
pi@raspberrypi ~ $ ping 192.168.1.52
PING 192.168.1.52 (192.168.1.52) 56(84) bytes of data.
64 bytes from 192.168.1.52: icmp_req=1 ttl=64 time=0.169 ms
64 bytes from 192.168.1.52: icmp_req=2 ttl=64 time=0.139 ms
64 bytes from 192.168.1.52: icmp_req=3 ttl=64 time=0.136 ms
^C
--- 192.168.1.52 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.136/0.148/0.169/0.014 ms
pi@raspberrypi ~ $ ping 192.168.1.15
PING 192.168.1.15 (192.168.1.15) 56(84) bytes of data.
64 bytes from 192.168.1.15: icmp_req=1 ttl=64 time=0.133 ms
64 bytes from 192.168.1.15: icmp_req=2 ttl=64 time=0.118 ms
^C
--- 192.168.1.15 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.118/0.125/0.133/0.013 ms


====================================================================================
when ping and SSH via local IP:

MacBook-Pro:~ kwc$ ping 192.168.1.52
PING 192.168.1.52 (192.168.1.52): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
^C
--- 192.168.1.52 ping statistics ---
5 packets transmitted, 0 packets received, 100.0% packet loss
MacBook-Pro:~ kwc$ ssh pi@192.168.1.52
ssh: connect to host 192.168.1.52 port 22: Operation timed out
Last edited by hiiragizawa on Wed Sep 02, 2015 6:26 am, edited 3 times in total.

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: Able to SSH via public IP but not local IP

Thu Aug 27, 2015 10:40 am

hiiragizawa wrote: 5. wlan0 has 2 IP addresses - one DHCP and one static.
I would start with that.
Quis custodiet ipsos custodes?

hiiragizawa
Posts: 4
Joined: Thu Aug 27, 2015 8:08 am

Re: Able to SSH via public IP but not local IP

Thu Aug 27, 2015 11:41 am

I was hoping not too touch the /network/interfaces file...

After experiencing multiple methods suggested across different forums, I found that most either don't work and screw up the Pi to the point I had no access to it and had to reimage the OS or it has the 2 IP address symptom... Took me almost a day experimenting.

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Able to SSH via public IP but not local IP

Thu Aug 27, 2015 11:47 am

Look at /etc/dhcpcd.conf. That's where the DHCP addresses are coming from.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Able to SSH via public IP but not local IP

Fri Aug 28, 2015 12:56 am

thanks to KNUTE viewtopic.php?p=798866#p798866
with original interfaces file but
sudo nano /etc/dhcpcd.conf ( add at end )

Code: Select all

interface eth0
static ip_address=192.168.1.101/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
interface wlan0
static ip_address=192.168.1.201/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 
you get ONE fix IP configured ( for eth0 and wlan0 each) and a good dhcpcdui ( network info top right of desktop)
Image
if you put a fix IP in /boot/cmdline.txt or /etc/network/interfaces
you get the DHCP double IP thing.
but actually it works too, just not that nice!

if you want to setup all for NOOBS RASPBIAN at the time you make the SD card already see viewtopic.php?p=799441#p799441

hiiragizawa
Posts: 4
Joined: Thu Aug 27, 2015 8:08 am

Re: Able to SSH via public IP but not local IP

Fri Aug 28, 2015 11:49 pm

Hi KLL,

Thanks for the step by step! I have one IP address now for the moment.

Let's see if this will make the WiFi connection stable... Will post updates accordingly.


===================================================================================
Details if someone ever bumps into this issue:

1. Run "sudo nano /etc/network/interfaces"
2. Edit the wlan interface you want with SSID & password. In this case, I used WPA, so:

Code: Select all

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wpa-ssid <wifi SSID/name here>
wpa-psk <wifi password here>

3. Save and exit

4. Run "sudo nano /etc/dhcpd.conf"
5. Append the following code:

Code: Select all

#static ip address configuration
interface wlan0
static ip_address=<ip address with mask, e.g. 192.168.1.52/24>
static routers= <router IP address, e.g. 192.168.1.1>
static domain_name_servers= <DNS IP, e.g. 192.168.1.1>
6. Save and exit

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Able to SSH via public IP but not local IP

Sat Aug 29, 2015 1:27 am

hiiragizawa wrote:wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wpa-ssid <wifi SSID/name here>
wpa-psk <wifi password here>
actually i delete the "wpa-conf" line if i configure the SSID /passwd in /etc/network/interfaces
because in that case any further setup by "dhcpcdui" or "run wpa-gui"
not makes much sense??

hiiragizawa
Posts: 4
Joined: Thu Aug 27, 2015 8:08 am

Re: Able to SSH via public IP but not local IP

Wed Sep 02, 2015 6:25 am

Hi all,

Just want to note that solving the DHCP and static IP address does not solve the SSH access issue.

I found out that the WiFi hardware that I had is faulty as I tested it against another USB dongle and the new USB WiFi works flawlessly.

However, if you have a faulty hardware, you would still be able to salvage it by doing a cron job to restart the network interface when the USB WiFi has issues.

The solution I came up with was pretty similar to this:
http://weworkweplay.com/play/rebooting- ... tion-wifi/

In short, use cron job and run the following batch:

Code: Select all

ping -c4 **ip address** > /dev/null
if [ $? != 0 ]
then
  echo "No network connection, restarting wlan0"
  /sbin/ifdown 'wlan0'
  sleep 5
  /sbin/ifup --force 'wlan0'
fi
Cheers!

Return to “Beginners”