Have you ever wanted setup a headless Raspberry Pi in your lab but don’t have an accessible DHCP server? Well, as it turns out, you can configure a static IP before you ever even load the OS! Follow along with this guide and I’ll show you how to do that by editing a single configuration file.
NOTE: For this example, I am using the Pi version Ubuntu OS, so your results may vary.
Requirements:
- Raspberry Pi
- MicroSD card
- Preinstalled OS (Installed on SD card)
Set Static IP via boot partition
- With the SD card inserted into your computer, navigate to the boot partition. In my case, this is the D drive.
- Locate the file named network-config and open it in the text editor of your choice. You should see the following if you’re using Ubuntu:
- Locate the network adapter for your desired connection, you should see dhcp4 is set to true to configure static IP. Remove the dhcp4 line.
- We’re going to modify this section by adding the following settings:
ethernets:
eth0:
addresses:
– ip.address.here/subnet
gateway4: gateway.address.here
nameservers:
addresses: [name.server.address.here]
optional: true - Ensure your file resembles this screenshot and save it.
- Remove the SD card from your computer, insert it into the Raspberry Pi, then boot the device.
At this point you should be able to use PuTTY to connect to your new static IP! If your network uses VLANs to segregate traffic, then there may be some additional configuration required. Go out there and enjoy your Raspberry Pi and remember, break it till you make it!
Pi’s don’t use Ubuntu. they use a version of Debian. so your `network-config` file flat out will NOT exist. you’ll have to create it. i’d just leave that comment out as it will throw many inexperienced Linux users for a bit of a loop. otherwise, great little tute. concise and useful, as every other one is for the bloody wifi, which, shocker, a lot of us never use. thanks for the post. 🙂
Hey Ian, thanks for the comment! Ubuntu does offer a version that is compatible with 64 bit Pi’s, you can find it here: https://ubuntu.com/raspberry-pi
You are right though, the Debian based OS does not have a network-config file. I should have clarified that. Thank you for pointing that out!
Also, I don’t think I’ve ever used the Wi-Fi on my Pi 😂