This post is a quick how-to article for configuring a static IP address on Raspberry Pi.
- Use the nano text editor to modify the /etc/dhcpcd.conf file with the following command:
sudo nano /etc/dhcpcd.conf
The nano text editor will open and display the contents of the /etc/dhcpcd.conf file.
- Press Alt + / to move to the last line of the file.
- Add the following lines to the end of the file:
interface eth0 static ip_address=192.168.0.10/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1
Adjust the values to suit your network environment.
Specifies the name of the network interface. On the Raspberry Pi this will generally be eth0, but could also be wlan0 if you are using a WiFi adapter.
Specifies the static IP address and subnet mask bits to be configured on the interface. A subnet mask of 255.255.255.0 equates to mask bits of 24. For other values, you can use the Subnet Calculator.
Specifies one or more router/gateway addresses to be configured on the interface. Multiple addresses should be space delimited.
Specifies one or more domain name service (DNS) server addresses to be configured on the interface. Multiple addresses should be space delimited.
- Press Ctrl + X to exit nano, press Y to save changes, and press Enter to confirm the existing filename.
- Reboot the Raspberry Pi, using the following command:
The Raspberry Pi will reboot immediately.
- Once rebooted, login to the Raspberry Pi. If you are connecting remotely via SSH, remember to use the new static IP address!
- Show the interface configuration, using the following command:
The command produces output similar to the following:
eth0 Link encap:Ethernet HWaddr b8:27:eb:d4:08:5a inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::82c3:4e6:21f:5763/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:138 errors:0 dropped:0 overruns:0 frame:0 TX packets:122 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12099 (11.8 KiB) TX bytes:18829 (18.3 KiB)
The Raspberry Pi is now configured to use a static IP address.
Raspberry Pi is a trademark of the Raspberry Pi Foundation.
Disclaimer: No liability is accepted (whether under the law of contract, the law of torts or otherwise) in relation to the contents of, or use of, or otherwise in connection with, this website to the extent that the website is provided free-of-charge, for any direct loss; for any indirect, special or consequential loss; or for any business losses, loss of revenue, income, profits or anticipated savings, loss of contracts or business relationships, loss of reputation or goodwill, or loss or corruption of information or data. These limitations of liability apply even when expressly advised of the potential loss.