Learn how to configure your Raspberry Pi for dynamic IP allocation using DHCP
A step-by-step guide on checking and setting up the Dynamic Host Configuration Protocol (DHCP) settings on your Raspberry Pi. …
Updated August 19, 2023
A step-by-step guide on checking and setting up the Dynamic Host Configuration Protocol (DHCP) settings on your Raspberry Pi.
To check and set up the Dynamic Host Configuration Protocol (DHCP) settings on your Raspberry Pi, follow these simple steps:
- Open a terminal window by clicking on the “Terminal” icon in the menu bar or pressing
Ctrl + Alt + T
. - Type
sudo nano /etc/dhcpcd.conf
and press Enter to open the DHCP configuration file in the nano text editor. You may be prompted for your password. - Scroll down through the file using the arrow keys or Page Down button until you find the lines starting with
interface eth0
. These lines define the network interface settings for Ethernet (wired) connections. If you’re using WiFi, look for a section starting withinterface wlan0
instead. - To check the current DHCP settings, look for a line that starts with
static ip_address=
. If this line is present, your Raspberry Pi is set to use static IP addressing and you’ll need to remove it to enable DHCP:- To delete the line, place the cursor on the line and press
Ctrl + K
until it’s highlighted. Then, save the file by pressingCtrl + X
, confirming your changes withY
, and hitting Enter.
- To delete the line, place the cursor on the line and press
- Now, add a new line to enable DHCP by typing
dhcp
on an empty line below theinterface eth0
orinterface wlan0
section and pressing Enter. Your configuration should look like this:
interface eth0
dhcp
- Save the changes by pressing
Ctrl + X
, confirming your changes withY
, and hitting Enter. Reboot your Raspberry Pi by typingsudo reboot
in the terminal and pressing Enter to apply the new settings. - After your Raspberry Pi reboots, check the IP address it was assigned by your DHCP server. Open a terminal window again and type
ifconfig
. Look for the “inet” address under the appropriate network interface (either eth0 or wlan0). This is your dynamic IP address. - To set a static IP address using DHCP, you can also configure the DHCP client on your router to always assign the same IP address to your Raspberry Pi based on its MAC address. Consult your router’s documentation for instructions on how to do this.
- To revert back to static IP addressing at any time, open
/etc/dhcpcd.conf
again and add a line likestatic ip_address=192.168.1.10/24
(replace the IP address with your desired static IP and subnet mask), save the file, and reboot your Raspberry Pi.
And that’s it! You now know how to check and configure DHCP settings on your Raspberry Pi. With DHCP enabled, you don’t need to manually set an IP address every time you connect your device to a network, making it much easier to manage multiple devices and avoid IP conflicts.