I got a Raspberry Pi running Raspbian, connected via Ethernet on my home LAN (on the ISP's default router). The router is configured to give addresses from 192.168.0.10
onwards with dhcp. I wanted to give a static ip to the Pi, so I assigned 192.168.0.9
to it by editing /etc/network/interfaces
as follows:
auto lo
iface lo inet loopback
# auto eth0
# allow-hotplug eth0
# iface eth0 inet manual
iface eth0 inet static
address 192.168.0.9
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.1.255
gateway 192.168.0.1
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
After rebooting and running ifconfig I see correctly(?) my ip to be 192.168.0.9
:
eth0 Link encap:Ethernet HWaddr b8:27:eb:d2:e5:5b
inet addr:192.168.0.9 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:fed2:e55b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17019 errors:0 dropped:16 overruns:0 frame:0
TX packets:1707 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2183986 (2.0 MiB) TX bytes:241230 (235.5 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:264 errors:0 dropped:0 overruns:0 frame:0
TX packets:264 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:21840 (21.3 KiB) TX bytes:21840 (21.3 KiB)
Yet, my router shows the raspberry to have an ip taken from dhcp (192.168.0.10
) and the weirdest thing is that I can access the Pi with ssh on both 192.168.0.10
and 192.168.0.9
ips. Any idea why that happens? How can I set the Pi to have only the static address I give to it?
Edit: For future reference: I found out that the problem is a bug of the last update of raspbian and others experience it as well (https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=111709)
Best Answer
How to set static IP address on Rasperry Pi Raspian
Don't use
/etc/network/interfaces
to set static IP. Use/etc/dhcpcd.conf
instead.Restore your
/etc/network/interfaces
to the original file, or undo your changes:Replace your changes with manual setting in
/etc/network/interfaces
:Configure dhcpcd:
Add your static profile options to the bottom of
/etc/dhcpcd.conf
:Remove leases:
Reboot:
Another option is to disable dhcpcd. After you disable dhcpcd, you can use
/etc/network/interfaces
instead to set static IP.Configure
/etc/network/interfaces
:Replace manual setting with static settings in
/etc/network/interfaces
:Configure dhcpcd:
Add the option to the bottom of
/etc/dhcpcd.conf
:Or you can disable the dhcpcd service:
Remove leases:
Reboot:
Source: