Raspberry Pi uses DHCP to configure its network interfaces by default. The IP address assigned by a DHCP server can change every time you start Pi.
If you want to access the Pi remotely, it should have a static IP address so you know exactly where you want to connect.
This article shows you how to assign a static IP address to the wired network interface port (eth0) of your Raspberry Pi running Raspbian OS.
1. Open a terminal window.
2. Backup the original network interface file :
$ sudo cp -p /etc/network/interfaces /etc/network/interfaces.original
3. Open the interfaces file in a text editor and change the line iface eth0 inet dhcp
to iface eth0 inet static
.
$ sudo nano /etc/network/interfaces iface eth0 inet static address 192.168.0.11 netmask 255.255.255.0 gateway 192.168.0.1
Press CTRL+X to exit. Then press Y to save the file and ENTER to accept the file name
4. Restart networking for the changes to take effect:
$ sudo /etc/init.d/networking stop $ sudo /etc/init.d/networking start
5. Verify settings:
$ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:61:f8:de
inet addr:192.168.0.11 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:818 errors:0 dropped:2 overruns:0 frame:0
TX packets:485 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:75805 (74.0 KiB) TX bytes:52483 (51.2 KiB)