How to Set a Static IP Address on Raspberry Pi

Static IP Address for Raspberry Pi
(Image credit: Shutterstock)

If you're trying to access a Raspberry Pi on your local network, there are times when you'll really need its IP address. Sure, you can usually SSH or VNC into a Pi by using its hostname, but for something like port forwarding on a router (which you'll use to create an externally-accessible Minecraft server or web server), an actual IP v4 address may be needed. The problem: every time you reboot your Pi, the IP address can change, based on what the router decides to assign at the moment.

Fortunately, there's a simple way to make sure that your Raspberry Pi always gets the same IP address on your local network or, at least, always tries to get the same address on your local network. It almost goes without saying that if, at the time it boots, another device that's powered on is already using the address in question, your Pi will either have no IP v4 address at all or (if you configured it as such) it will choose an alternative one. So keep that in mind.

Latest Videos FromTom's Hardware
Avram Piltch
Managing Editor: Special Projects

Avram Piltch is Managing Editor: Special Projects. When he's not playing with the latest gadgets at work or putting on VR helmets at trade shows, you'll find him rooting his phone, taking apart his PC, or coding plugins. With his technical knowledge and passion for testing, Avram developed many real-world benchmarks, including our laptop battery test.

  • AusMatt
    Typo:
    grep "namesever" /etc/resolv.conf
    Should read:
    grep "namersever" /etc/resolv.conf
    Reply
  • alan tracey wootton
    With an Arduino that is serving a web page one can use mDns instead of keeping track of the local IP address.
    Add this to your Setup():
    if (MDNS.begin("esp32"))
    {
    MDNS.setInstanceName("count server demo");
    MDNS.addService("http", "tcp", 80);
    MDNS.addServiceTxt("http","tcp","counter","true");
    }Then that webpage is available locally in chrome and safari as:
    http://esp32.local./I didn't test the other browsers.
    I'm sure this works for a Pi also even though I haven't tried it yet. mDns might be on by default.
    The url would be http://raspberrypi.local./To check, try this command:
    dns-sd -B _http._tcpWhen I do that I find that both of my printers are serving http (a supply level page) in addition to the microcontroller.
    Reply
  • wl84
    When I run the nameserver command I get two results back - 192.168.11.1 and 192.168.68.1. I tried both in the config and I can't connect to anythign with either. I'm trying to setup pihole
    Reply