How to set static IP address in Raspbian?
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
- Login to Raspbian
- Make backup of network settings
1sudo cp /etc/network/interfaces /etc/network/interfaces.bak
- Edit file
1sudo nano /etc/network/interfaces
- Put settings in file
- address - static IP addres
- netmask - local network mask
- gateway - local network gateway
1auto lo 2iface lo inet loopback 3 4iface eth0 inet static 5address 192.168.0.2 6netmask 255.255.255.0 7gateway 192.168.0.1
- Save changes
- Delete cache DHCP
1sudo rm /var/lib/dhcp/* 2sudo rm /var/lib/dhcpcd5/*
- 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
1interface eth0 2static ip_address=192.168.0.2/24 3static routers=192.168.0.1 4static domain_name_servers=184.108.40.206
- ip_address - static IP address
- domain_name_servers - IP addresses of DNS (in this example it's google DNS).