2

I have set up a new installation of NOOBS on a Raspberry Pi 2. I configured a static IP address by adding this to /etc/dhcpcd.conf:

interface eth0
static ip_address=192.168.2.102/24
static routers=192.168.2.0
static domain_name_servers=192.168.2.1

However, there doesn't seem to be any default gateway now, so I can't access the internet:

$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     *               255.255.255.0   U     202    0        0 eth0
$ ping -c 1 google.com
connect: Network is unreachable

If I manually add it, everything works:

$ sudo route add default gw 192.168.2.1 eth0
$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
192.168.2.0     *               255.255.255.0   U     202    0        0 eth0
$ ping -c 1 google.com
PING google.com (216.58.220.142) 56(84) bytes of data.
64 bytes from syd09s01-in-f142.1e100.net (216.58.220.142): icmp_seq=1 ttl=57 time=6.45 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 6.457/6.457/6.457/0.000 ms

But this needs to be done every time I reboot. I tried adding:

auto eth0

to /etc/network/interfaces as suggested on another forum but it made no difference.

Am I missing something?

Here is the contents of my /etc/network/interfaces:

source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
aco
  • 131
  • 1
  • 1
  • 5

1 Answers1

1

After a lot of fiddling and searching, I found I had a typo in /etc/dhcpcd.conf. This line:

static routers=192.168.2.0

should be:

static routers=192.168.2.1

After fixing that, everything now works.

aco
  • 131
  • 1
  • 1
  • 5