Static IP Configuration for your Raspberry Pi

Static IP

If you are using your Raspberry Pi to host services like web servers, DNS, or the like. A dynamic IP can be problematic if it changes. In this case, you should configure your device with a Static IP.

All versions of Raspbian since Raspberry Jessie have been configured by editing dhcpd.conf You can do this with a local keyboard. Alternatively, as the changes don’t take effect until reboot you can do it over SSH. SSH can be easier as you can copy and paste the example from here rather than typing everything manually. From the command line run

sudo nano /etc/dhcpcd.conf

You will see a screen similar to the one below.

Nano dhcpd.conf

Next scroll to the very bottom of the file. If you are trying to set a Static IP on the ethernet port (wired) you use interface eth0. If it is the wireless connection (Wi-Fi) the interface is wlan0. You can set up both if your device has both interfaces but make sure their IP addresses are unique.

Copy one or both of the examples below. Editing the numbers to properly reflect your network. See the Variables Section.

Ethernet

interface eth0

static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

Wireless

interface wlan0

static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

Once you have made the appropriate changes.
Press Ctrl + x to exit.
When prompted hit Y then Enter to save and exit

Once back at the command prompt you need to reboot for the configuration to take effect. Run

sudo reboot

Once the Raspberry Pi has rebooted you should be able to connect with the new IP address.

Variables

interface = eth0 or wlan0 depending on the connection type.
static ip_address = The IP address that you want to give your device to. The /24 at the end is important and should be correct for most home networks.
static routers = The IP address of your default gateway, generally this is your router.
static domain_name_servers = Your DNS address(es) – Often the IP address of your router. Additionally, you can have multiple DNS addresses separated by a single space.

You may also like...