1

first of all let me say I'm a beginner so assume I don't know anything. Okay, now my problem. I'm trying to set up my old PI2 to be a terraria server to play with some friends. Everything was working fine but at some point my pi2 stopped being connected to internet (i'm using an ethernet). I've looked online but none of the things i've done worked. Any suggestions? I think it may be related to some DHCP problems but as I said i'm a beginner and I don't even know what DHCP is. Thanks for the help.

PS: among the things that I tryied i guess this one was the only one worth telling:

sudo nano /etc/dhcpcd.conf

then

interface eth0
static ip_adress=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

where "192.168.1.1" is my router's adress

Sorry again if I made some stupid mistakes/assumpions but i'm a beginner and I know very little.

EDIT: This is the output log of some commands I've been suggested to try:

pi@raspberrypi:~ $ sudo ping 192.168.1.1
connect: Network is unreachable
pi@raspberrypi:~ $ sudo ping 4.2.2.4
connect: Network is unreachable
pi@raspberrypi:~ $ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether b8:27:eb:26:9a:72  txqueuelen 1000  (Ethernet)
        RX packets 320  bytes 15316 (14.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 4784 (4.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

pi@raspberrypi:~ $ sudo ip -4 addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
pi@raspberrypi:~ $ sudo ip -4 route show
pi@raspberrypi:~ $ sudo cat /etc/resolv.conf
nameserver 8.8.8.8pi@raspberrypi:~ $ 
7
  • Hello and welcome -- "Everything was working fine but at some point my pi2 stopped being connected to internet', how you deduced that the internet is not accessible for the raspberry pi? -- Try ping 192.168.1.1 to find out are the pi connected to router or not. Then, ping 4.2.2.4 to check google dns servers is accessible. The output should not be the request time out ... or host unreachable ... Commented Feb 3, 2020 at 17:31
  • 1
    In this case, there is a lot of possibilities. It would be helpful to add the output of these commands to the question body. -- ifconfig | ip -4 addr show | ip -4 route show | cat /etc/resolv.conf Commented Feb 3, 2020 at 17:35
  • I'll try to explain better, sorry. Basically as soon as I started it my pi2 wasn't connected to the internet (i'm running some kind of gui and it just says "disconnected"). But in an afternoon of trying, out of nowhere it started to work. So I just went on with my business. Then, the pi2 froze and I had to reboot and then the internet connection was gone again. Just to be sure, the ethernet cable works just fine (writing this from my desktop with the same ethernet) I've done all of the things you asked me to and here's the log. I'll put it in the body too. Thank you for your help.
    – Nicola
    Commented Feb 3, 2020 at 19:22
  • 1
    Setting a static IP address is not necessary, and if wrong causes problems. Delete all the stuff you put in dhcpcd.conf and let the network do its job. If you still have problems describe the status lights on the Ethernet interface.
    – Milliways
    Commented Feb 3, 2020 at 23:57
  • @M.Rostami DO NOT advise people to run deprecated commands - tell them how to do it properly.
    – Milliways
    Commented Feb 4, 2020 at 0:01

2 Answers 2

1

Already the first command ping 192.168.1.1 with "Network is unreachable" shows that your connection to your router is broken. It seems that there is no ethernet cable connected to the router (I know there is). I don't know what you already have tried but the first step would be to check the ethernet cable. Maybe it's broken or has a bad connection. Try another cable. It's also possible that your router is down. Reboot it. It is important for the first step that ping 192.168.1.1 gives you a reply, something similar to this:

pi@raspberrypi:~ $ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.39 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.68 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=2.38 ms

--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 6ms
rtt min/avg/max/mdev = 1.388/1.813/2.375/0.414 ms

There may be another issue with your ip address. You have given your RasPi a static ip address, routers and domain_name_servers in /etc/dhcpcd.conf. It may be possible that this conflicts with another device on the network having the same ip address 192.168.1.200. Ip adresses are usually managed by a DHCP server mostly running on the router. It depends on how the router manages such conflicts. I know router that will disconnect the conflicting line (your ethernet cable). Try to just comment the three static entries in /etc/dhcpcd.conf and reboot the RasPi. Then it should get a valid ip address from the router/DHCP server and other needed options.

2
  • The ethernet cable works just fine, and I'm 100% sure about that. I'm using it right now to surf on my desktop. I understand that the problem is that at the moment it looks like the ethernet isn't working but that's what I'm trying figure out! Any other ideas? Thanks for your help!
    – Nicola
    Commented Feb 3, 2020 at 20:02
  • @Nicola I have updated the answer.
    – Ingo
    Commented Feb 3, 2020 at 20:06
1

Comment or remove these lines of /etc/dhcpcd.conf:

interface eth0
static ip_adress=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

If the router does its job (DHCP server is enabled), the raspberry pi would get an IP address from the router. Therefore, after removing these four lines, try to check that is router reachable for raspberry pi or not:

ping 192.168.1.1 -c 3 

By this command, you'll send three ICMP packet to the router and if it's reachable it will say you (on statistics part of output) 3 packets transmitted. If it's not worked and says request time out ... or host unreachable ..., you should troubleshoot this situation.
At first, try to realize that is there any DHCP server enabled on the router which you have connected raspberry pi to:

ifconfig eth0

And the output should be something like this:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.150  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::fe99:6c74:e7bd:1883  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:2a:8f:d5  txqueuelen 1000  (Ethernet)
        RX packets 1660  bytes 109201 (106.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 345  bytes 45728 (44.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  

Look at the inet 192.168.1.150 netmask 255.255.255.0 section. It means that the raspberry pi gets an IP address which is 192.168.1.150. Next, you need to find gateway's IP address which is the IP address of the router:

route -n

It will give you the gateway's IP address which can be something between 192.168.1.0 to 192.168.1.254 and of course it's not 192.168.1.150. After that, like previous procedures, ping that address to ensure the connectivity.

NOTE: If you couldn't find any IP address when you run ifconfig eth0, it's not the raspberry pi's fault. You need to check out your local network configuration to find the problem.


If all the procedures above would be successful in your case, you can try the internet connectivity by pinging 8.8.8.8 or www.google.com.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.