4

Hardware: Pi 2

OS: Raspberry Pi OS 32-bit

No firewall. Running over ethernet (no WiFi card)

I am following a tutorial to set up a Pi as a file server for home. For this, I need to install Samba. Whenever I run sudo apt-get install samba samba-common-bin and confirm disk space usage, I get the following output:

Err:1 http://mirrors.switch.ca/raspbian/raspbian buster/main armhf python-dnspython all 1.16.0-1
Cannot initiate the connection to mirrors.switch.ca:80 (209.115.181.106). - connect (101: Network is unreachable)
E: Failed to fetch http://mirrors.switch.ca/raspbian/raspbian/pool/main/d/dnspython/python-dnspython_1.16.0-1_all.deb  Cannot initiate the connection to mirrors.switch.ca:80 (209.115.181.106). - connect (101: Network is unreachable)
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Of course the first thing I tried was to ping mirrors.switch.ca at the IP 209.115.181.106, which returned :

connect: Network is unreachable

However, pinging anything like google.com or facebook.com is successful, while pinging something like 8.8.8.8 returns the above message. (Pinging any of the above IPs from my Windows PC works. Both my PC and Pi are connected to the same router via ethernet)

At this point, after doing some digging, I also noticed that my initial sudo apt-get upgrade after setting up the Pi failed for the same reason.

Following the accepted answer on this question, I added dns-nameservers 8.8.8.8 8.8.4.4 to be the last line of /etc/network/interfaces and nameserver 8.8.8.8 8.8.4.4 as the last line of /etc/resolve.conf. After these changes, I was able to successfully run sudo apt-get upgrade, but sudo apt-get install samba samba-common-bin continues to return the same error message.

This is the output from ifconfig:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet  192.168.0.10 netmask 255.255.255.0 broadcast 192.168.0.255
        inet6 2607:9880:3310:4a:6387:cd42:1739:7bd7  prefixlen 64 scopeid 0x0<global>
        inet6 2607:9880:3310:4a::c58f  prefixlen 128  scopeid 0x0<global>
        inet6 fe80::155b:afb7:2eca:cfed  prefixlen 64 scopeid 0x20<link>
        ether b8:27:eb:40:5c:53  txqueuelen 1000 (Ethernet)
        RX packets 6744  bytes 1301368  (1.2MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 712  bytes 85209 (83.2 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

I also made some configuration changes when setting up the Pi to allow SSH connections. If this config is relevant, I will post it.

edit - SSH config: To set up for SSH, I started by creating an empty file: sudo touch boot/ssh Then I edited /etc/dhcpcd.conf to uncomment the lines with interface eth0 and static ip_address=..., and set the IP to 192.168.0.10/24

This is the result from route print on my Windows machine: enter image description here

Please note that I am a beginner with this tech.

Thank you.

Seamus
  • 21,900
  • 3
  • 33
  • 70
Daniel F
  • 43
  • 1
  • 4
  • DNS is not your problem. Your error message says: connect: Network is unreachable. That means your packets are not being routed to the correct network. You may confirm this by running traceroute from your RPi. – Seamus Aug 04 '20 at 19:17
  • @Seamus you're right, I'm getting "Network is unreachable" for all IPs when I do a traceroute, including ones that were otherwise working (google.com). Running traceroute to my PC appears to work just fine. What should I do going forward? – Daniel F Aug 04 '20 at 20:05
  • @Milliways the first line of the linked answer is: "This Answer is obsolete. The operation of mirrordirector has changed." Please provide more information. – Cristian C. Aug 04 '20 at 22:49
  • If this is the "linked answer", it's irrelevant - at least until you solve your connectivity problem. Run the command route -n on your RPi - what does it show? – Seamus Aug 04 '20 at 23:27
  • @Seamus Destination: 192.168.0.0 Gateway: 0.0.0.0 Genmask: 255.255.255.0 Flags: U Metric: 202 Ref: 0 Use: 0 Iface: eth0 – Daniel F Aug 05 '20 at 13:21
  • That's not right. You said, "made some configuration changes when setting up the Pi to allow SSH connections". *Edit your question* to add those configuration changes you made. Also post the routing table from your Windows machine for comparison. Use the route print command - here's how. – Seamus Aug 05 '20 at 19:15
  • @Seamus I updated the question with the info you requested – Daniel F Aug 05 '20 at 20:31
  • I think your problem is the change you made to dhcpcd.conf. I'll explain what you should have done in my answer, but for now, let's make a quick test: Restore your dhcpcd.conf to its original state, and reboot your Pi. That should restore your gateway route (which is part of what DHCP does), and give you connectivity. Can you do that? – Seamus Aug 05 '20 at 21:43
  • @Seamus Yep, restoring dhcpcd.conf solved my connectivity issues. I'll accept your answer once you post it. Thank you for your patience and assistance! – Daniel F Aug 05 '20 at 23:33
  • Glad that helped. Let me know if you have any questions on my answer. – Seamus Aug 05 '20 at 23:54
  • Daniel - As it has turned out, your question actually had little to do with installing Samba. Therefore, if you have no objections, I'd like to edit the title of your question to more clearly reflect the problem: "Cannot reach Internet after assigning fixed IP address in dhcpcd.conf" Are you OK with this? – Seamus Aug 06 '20 at 06:03
  • @Seamus Good point. I'm ok with that – Daniel F Aug 06 '20 at 13:30

3 Answers3

3

When you changed /etc/dhcpcd.conf to make it a static IP, it's likely you broke your Raspberry Pi's connectivity. dhcpcd is your DHCP client. Its job is to communicate with your DHCP server (usually your router/cable modem/etc) to obtain the following items:

  • an IP address for your host machine
  • the IP address of the local gateway
  • the IP address of a DNS server

When you change /etc/dhcpcd.conf to use a static IP address as you did, you are telling dhcpcd to "butt out" - you're telling dhcpcd that you don't need its services. And that's fine, but you must now supply the missing information: a gateway and a DNS.

With zeroconf networking you don't need a fixed IP address to run a file server on your LAN. Repeat after me: "I do not need a static IP to run a file server. I do not need a static IP to connect to my RPi from another host. I do not need a static IP. If I think I need a static IP, I shall think again."

You may be thinking that you still want a fixed IP address, but without having to deal with these other messy issues. I have good news for you: In this case, you can "have your cake, and eat it too": dhcpcd.conf has an option called inform that will give you the address you want, and not change it - details here. Note there are caveats (see man dhcpcd.conf), but they're unlikely to affect you on a small LAN.

Seamus
  • 21,900
  • 3
  • 33
  • 70
0

Your resolv.conf file should look like this if you are using Google DNS.

    pi@raspberry:/var/www $ cat /etc/resolv.conf
    # Generated by resolvconf
    domain Home
    nameserver 8.8.8.8
    nameserver 8.8.4.4
  • Every time I make a change to this file and reboot, it gets rewritten to its original (3 nameserver entries with IPv6 addresses). So my nameserver 8.8.8.8 8.8.4.4 was not saved, and neither were the changes you suggested. Thoughts? – Daniel F Aug 04 '20 at 16:28
  • Did you sudo when you did the edit? – tunafreedolphin Aug 04 '20 at 16:34
  • Yeah sudo nano /etc/resolv.conf – Daniel F Aug 04 '20 at 16:36
  • resolve.conf is created every boot so changes are overwritten. The gateway address should come from you DHCP server - normally the home router. –  Aug 04 '20 at 21:31
  • Search google for how to configure the resolvconf package. Or, like me, just rip that piece out of your RaspiOS systems. – Dougie Aug 04 '20 at 22:10
0

"Then I edited /etc/dhcpcd.conf to uncomment the lines with interface eth0 and static ip_address=..., and set the IP to 192.168.0.10/24"

This is incompatible with /etc/network/interfaces

Remove the non-standard settings and revert to a normal Raspberry Pi OS configuration. This is explained in How to set up networking/WiFi.

If you REALLY want a Static IP Address the following explains How to set up Static IP Address

DO NOT attempt to set /etc/resolv.conf (by any means) - this is done automatically by dhcpcd

Milliways
  • 59,890
  • 31
  • 101
  • 209