Option 1 – set static IP address in router
Many routers have settings to assign static IP address based on MAC addres of network card.
Each router has different administration panel, so I won’t describe this option in detail.
If IP address of your local network is 192.168.0.15 you probably can access in browser “http://192.168.0.1/” to administration panel of router.
When you choose option 2 or 3 you should configure DHCP server to assign dynamic IP only from selected range.
In my router settings looks like:
Now DHCP server will assign newly connected devices IP address from range 192.168.0.20 – 192.168.0.254.
Therefore you can set static IP in range 192.168.0.2 (ending “1” is router address) to 192.168.0.19.
Option 2 – edit file /etc/network/interfaces
1) Login to Raspbian
2) Make backup of network settings
sudo cp /etc/network/interfaces /etc/network/interfaces.bak
3) Edit file
sudo nano /etc/network/interfaces
4) Put settings in file
- address – static IP addres
- netmask – local network mask
- gateway – local network gateway
auto lo iface lo inet loopback iface eth0 inet static address 192.168.0.2 netmask 255.255.255.0 gateway 192.168.0.1
4) Save changes
CTRL+x, Y [yes]
5) Delete cache DHCP
sudo rm /var/lib/dhcp/* sudo rm /var/lib/dhcpcd5/*
6) Restart system
Option 3 – dhcpcd.conf
When there is comment in file /etc/network/interfaces (for example Raspbian 1.5):
# Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
you should change file “/etc/dhcpcd.conf”:
interface eth0 static ip_address=192.168.0.2/24 static routers=192.168.0.1 static domain_name_servers=22.214.171.124
- ip_address – static IP address
- domain_name_servers – IP addresses of DNS (in this example it’s google DNS).