Can ping but can't connect (curl, wget, apt-get, etc.) (rasberry pi server)

18,376

This seems like a DNS lookup problem. Can you test something like:

nslookup www.google.com

If it responds with an IP address, then you have your DNS working, otherwise, you need to fix you DNS issue first by editing your /etc/resolv.conf to contain something like:

nameserver 8.8.4.4

Share:
18,376

Related videos on Youtube

chase
Author by

chase

Updated on September 18, 2022

Comments

  • chase
    chase over 1 year

    Background: I am trying to set up a rasberry pi server. Everything was going well and my pi could apt-get update etc, until I got the port forwarding to work and ssh to work outside of the LAN. I have been trying to get a webpage up as well so I created a port forward for a port other than 80, since my ISP was blocking it.

    Problem: After getting access to the pi by ssh outside LAN, I was unable to use apt-get or get any connection to websites with my pi. The ping is still working well though.

    What I have tried: I have tried many different configurations of the iptables, as well as completely flushing it and starting over several times with configurations people have suggested. None of it seems to work. At the moment, the iptables are completely flushed.

    Here is an example output of the pings and wget/curls:

    pi@raspberrypi:~$ sudo apt-get update
    0% [Connecting to mirrordirector.raspbian.org (5.153.225.207)] [Connecting to w^Cpi@raspberrypi:~$ wget -q -O- google.com
    ^C
    pi@raspberrypi:~$ ping google.com
    PING google.com (74.125.224.98) 56(84) bytes of data.
    64 bytes from lax02s19-in-f2.1e100.net (74.125.224.98): icmp_req=1 ttl=52 time=58.8 ms
    64 bytes from lax02s19-in-f2.1e100.net (74.125.224.98): icmp_req=2 ttl=52 time=53.8 ms
    64 bytes from lax02s19-in-f2.1e100.net (74.125.224.98): icmp_req=3 ttl=52 time=62.2 ms
    64 bytes from lax02s19-in-f2.1e100.net (74.125.224.98): icmp_req=4 ttl=52 time=71.2 ms
    64 bytes from lax02s19-in-f2.1e100.net (74.125.224.98): icmp_req=5 ttl=52 time=67.3 ms
    ^C
    --- google.com ping statistics ---
    5 packets transmitted, 5 received, 0% packet loss, time 4005ms
    rtt min/avg/max/mdev = 53.846/62.705/71.224/6.137 ms
    pi@raspberrypi:~$
    

    I have to ctrl-c out of the tasks obviously because they hang, but that's the output.

    Does anyone know what other problem may be causing this?

    EDIT

    I found the problem was somehow my ip adress was added to the port blocking in my router, so if you have similar problems check that even if you don't believe you touched it.

    • Admin
      Admin over 9 years
      if you are pinging the public address of a system that is performing port forwarding, you are pinging the router, not the server. are you pinging the server from within or outside its LAN? I'd also install UFW and make sure it is configured to allow outgoing connections and incoming responses. iptables is powerful, but often unnecessarily complicated.
    • Admin
      Admin over 9 years
      I am trying to ping addresses outside my LAN from my server. I would like the server to have the ability to connect to the internet and download files as needed so I can ssh into it and do work or add things as necessary.
    • Admin
      Admin over 9 years
      OK, this seems pretty confusing now. So you have a your machine (call it rp) behind your router and you have forwarded ssh and http on say 8080 port to your rp on your router and after this your rp cannot ping Google or download files from Internet?
    • Admin
      Admin over 9 years
      Almost - everything you said except it actually can ping, just not download.
    • Admin
      Admin over 9 years
      post your pi's iptables and your router's configuration.
  • chase
    chase over 9 years
    apparently I don't have nslookup as a command, but I added the nameserver 8.8.8.8 and nameserver 8.8.4.4 to the file and the problem persists. I did not have those values already in the file, it was three other ip's which I believe were primary WAN DNS, secondary WAN DNS, and third WAN DNS.
  • chase
    chase over 9 years
    I noticed after rebooting the resolv.conf file returns to having only the three entries in it and deletes the 8.8.8.8 and 8.8.4.4 entries..... I don't know if it should do that but I wouldn't think that is normal.
  • Mahdi
    Mahdi over 9 years
    Sorry, I forgot to mention that after editing that file you need to restart your network services. Do you manually set your IP or it is from DHCP (automatic)?
  • Mahdi
    Mahdi over 9 years
    When you ping a host (e.g. ping www.google.com) will you get an IP address for it and is it successfull? BTW, you can get nslookup by installing dnsutils package: sudo apt-get install dnsutils
  • chase
    chase over 9 years
    My ip is set dynamically. I tried restarting the network services after adding the nameservers but it still gives me nothing on curl or wget commands and hangs at 0% [Connecting to mirrordirector.rasbpian.org ]
  • chase
    chase over 9 years
    The pings are successful. They are able to transmit packages and everything. I can't get the dnsutils because apt-get doesn't work.
  • chase
    chase over 9 years
    I added some of the output from wget and ping to my question.
  • chase
    chase over 9 years
    Well, I can't get lynx to check since apt-get doesn't work. However, startx used to start the GUI OS, but now it times out due to some xauth error from /var/www/.XAuthority
  • Mahdi
    Mahdi over 9 years
    You can wget it :p
  • chase
    chase over 9 years
    wget does not work. that's the problem....
  • Mahdi
    Mahdi over 9 years
    Can you disable your port forwarding to get internet back to the machine?!