24

I'm having a problem with my Raspberry Pi where I can't ssh into or even ping it, yet I'm using it on my TV, and it's clearly connected to the network/Internet.

I've used the attached keyboard to run several curl commands, wget, and apt-get update, and they all work fine, but I can't connect to it remotely using the IP address, and it won't respond to pings. I've just freshly installed Raspbian, and so far all I've done is set up Wi-Fi, which is clearly working.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
19wolf
  • 363
  • 1
  • 3
  • 6
  • Does your computer that you're sshing from have a firewall ? Have you double checked the IP address with /sbin/ifconfig just in case it's not the correct one ? – Lawrence Feb 06 '14 at 00:57
  • 1
    No, it actually worked fine right before i rebooted for the first time after I setup the wifi (I ssh-ed to make sure it worked, then rebooted, at which point it stopped working). I double checked the IP with "ifconfig wlan0" and found it to be the same as it has been. – 19wolf Feb 06 '14 at 01:01
  • update: I restarted it for the 20th time and it is now working... – 19wolf Feb 06 '14 at 01:10
  • plz paste your ifconfig – Alex Tape Feb 06 '14 at 09:16
  • I had a similar experience with a SD card corrupted by an inefficient power supply. – rob Feb 06 '14 at 11:22
  • 2
    This might be a power saving issue with your wifi dongle. Try to maintain it busy with eg ping google.com on the Pi and try ssh'ing at the same time. – M Noit Feb 06 '14 at 11:26
  • @MNoit, this was it for me, thanks! Now to work out how to disable this 'feature'. – Joshua Walsh Feb 26 '15 at 10:45
  • I don't see how it can be a power/dongle issue if the pi does connect to internet. I can ping google fine, but sometimes can't ping the pi from within the network, despite fixed ip etc.. – geotheory Apr 23 '15 at 09:57

4 Answers4

14

This happens a lot with one of my Raspberry Pis. I have a script which checks for an Internet connection and runs ifup wlan0 when a connection is not present. Some of the things you could try:

  • Rebooting the Raspberry Pi
  • Checking that you have a valid IP address using ifconfig
  • Ensuring that you have power-saving features disabled on the dongle by adding wireless-power off to your /etc/network/interfaces file
  • Run ifup --force wlan0

Here's a script which runs every five minutes from cron:

#!/bin/bash
#Script to check the network connection

#Check network connection
if /sbin/ifconfig wlan0 | grep -q "inet addr:" ; then
    #Connection is good; do nothing
    echo "$(date "+%D [%H:%M:%S]") Connection is up"
else
    echo "$(date "+%D [%H:%M:%S]") Network connection down. Attempting to reconnect..."
    sudo /sbin/ifup --force wlan0
fi

If that is a wireless card power management issue, you can also have a look at WLAN disappears after some time.

Many wireless network cards don't support wireless-power off option in /etc/network/interfaces. To disable power management with a 8192CU module loaded, you can create a file sudo nano /etc/modprobe.d/8192cu.conf with the following contents.

# Disable power management
options 8192cu rtw_power_mgnt=0
Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
nagyben
  • 773
  • 6
  • 10
  • The internet connection is working and has a valid IP address, though I think your suggestion of adding "wireless-power off" has worked. If it doesn't fail in the next few days I'll accept your answer. – 19wolf Feb 09 '14 at 21:45
  • Did the fix work? I am facing the same problem. – zengr Apr 10 '14 at 23:22
  • @exantas: Can you share that script? I think I will need it too. – zengr Apr 10 '14 at 23:24
  • @zengr: edited my answer – nagyben Apr 10 '14 at 23:30
  • ah, the problem I am having is, I see inet addr: in ifconfig and I have a valid IP address but I am not able to ping/wget etc. – zengr Apr 10 '14 at 23:37
  • can you ssh into it? – nagyben Apr 10 '14 at 23:38
  • no, I cannot. I have plugged in a monitor and using it for now. – zengr Apr 10 '14 at 23:41
  • What dongle are you using? – nagyben Apr 10 '14 at 23:46
  • Ralink RT5370. It connects to the internet, works if I don't do anything. But if I do apt-get install nmap (or anything else) it hangs at random say at 48%. And after that, ping, ssh etc do not work. – zengr Apr 10 '14 at 23:58
  • Did you follow any of the suggestions in my answer e.g. turning power saving off? – nagyben Apr 11 '14 at 00:05
  • yup, tried that. I don't think power is an issue because it stops working within seconds if I do some data intensive activity like pull data over the internet. – zengr Apr 11 '14 at 00:10
  • I think you've found the cause of your problem but unfortunately I have no idea why that would happen. Could be anything, even a power supply issue... – nagyben Apr 11 '14 at 00:11
  • posted a new question here: http://raspberrypi.stackexchange.com/questions/15142/wifi-drops-on-raspberry-pi – zengr Apr 11 '14 at 23:10
  • I was unable to download anything and it kept failing, now seems the only reason was because of the power management issue. Thanks. – King Friday Sep 22 '15 at 03:09
  • This happend to my Raspberry PI 3 Model B on Raspbian Jessie Lite (version February 2016). Thank you for this answer, it worked. – narzero Mar 02 '16 at 15:47
3

I have found myself in this issue before. Sometimes my router would pick up the wrong IP address. To fix the issue I used nmap to find my Raspberry Pi. I think that the command was nmap 192.168.1.0/24.

That should be able to find the IP address and help you to ssh and ping. If you are connected by a monitor then run ifconfig inside the terminal application.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
iProgram
  • 329
  • 1
  • 4
  • 12
2

I was having similar problems. With an Ethernet connection I could remote desktop from my PC into the Raspberry Pi, but with Wi-Fi the connection failed; I couldn't even ping the Raspberry Pi.

It turned out to be a router problem. I created a new rule for routing port 3389 (used by RDP) to the IP address of the Raspberry Pi (I also setup the router to assign the same IP address to the MAC address of the Raspberry Pi Wi-Fi). This resolved the problem. Ping still fails sometimes; I suspect that is more related to the power management solution mentioned above.

I found the instructions for my NetGear router setup in Port Forwarding the Netgear WGT624v3 Router for Remote Desktop.

Eugen
  • 488
  • 3
  • 12
MikeT
  • 21
  • 1
0

try using raspi-config and enable ssh from interface option.

  • 3
    Will enabling SSH in the raspi-config fix the issue with ping? OP wrote: "I can't [ ] even ping it." – techraf Mar 15 '17 at 02:59