User Tools

Site Tools


tutorials:pistaticip

Setting A Raspberry Pi's Static IP

For almost everything you want a pi for with XTension it is helpful to have it set to a static IP that XTension will always know to talk to it. You can use DHCP Reservations in your router, but then you loose all the settings if the firmware is reset or you get a new router. You can use mDNS/Bonjour names but in my experience those are not always updated properly. They may work for a year and then just not be there until you restart the device in question. So setting static IP’s still the best way.

With the release of the Bullseye versions of Raspian OS they have dramatically changed how this is setup. This article will show the procedure for both Bullseye and previous versions of the OS via the command line. If you have the full version of the OS and access to the UI via a connected monitor or VNC then setting it through the UI is simple.


Setting a Static IP On Bullseye

Bullseye uses the new Network Manager on the command line. Step one is to get the information on the network devices and their name, which is what you use to reference them when setting them up. So you no longer use the old standards of “eth0” and “wlan0” but the connection names that are given to them.

From the command line:

$ nmcli device status

Which will result in output something like this:

DEVICE         TYPE      STATE                   CONNECTION         
eth0           ethernet  connected               Wired connection 1 
lo             loopback  connected (externally)  lo                 
wlan0          wifi      disconnected            --  

We want to set the static IP for the Wired Connection so we’re going to use the name “Wired connection 1” if you were setting it up for wifi you’d use whatever name the system had given to that in the above output. Mine is disabled so it does not have a name.

To edit the settings for the connection the command is:

$ sudo nmtui edit “Wired connection 1"

You’ll get a page that is similar to the raspi-config using the terminal as a pretend graphical interface. This can also be done using the nmcli command line program, but that is more complicated and more chance of a user error. If you want to use that you’re probably not reading this tutorial anyway.

Use your tab key to navigate to the IPv4 Configuration where it will say “<Automatic>” hit return to bring up the popup menu and select “<Manual>” instead, that will make the rest of the fields in the screen shot visible. Tab down to “<add>” and select that, then enter the IP address you wish the device to have.

You will also need to know the netmask bits, thats the “/24” portion of the “192.168.0.245/24” in the example above. Most home networks are setup to use a netmask of 255.255.255.0 in which case it should be “/24” like mine, if yours uses 255.255.0.0 then the proper setting is “/16” If you have other settings then you probably set them up specifically and you already know what that should be.

Set the Gateway address and the DNS Servers. If you don’t enter anything into the DNS Server field it will almost certainly default to using the gateway which is what you normally want. If you wish to enter specific ones do so there.

Keep tabbing until you get to the bottom of the screen which is off the bottom in a default sized terminal window and select to save.

to make it active use the command:

$ sudo systemctl restart NetworkManager

The fun part about this new network manager is that it will not disconnect your current session when you change the IP address. The original IP will remain active until you either specifically remove it or reboot the machine.

To check the status of the device you can use:

$ nmcli device show eth0 

then reboot the machine.


Setting Static IP on Rasbian Versions Prior To Bullseye

Get The Subnet Bits

You need to know the subnet portion of the address in order to set it up. Generally if you are using a subnet of 255.255.255.0 then the bits portion will be “/24” and if you’re using 255.255.0.0 then the bits portion will be “/16” but you can verify by using the command:

$ ip -v4 addr show

The output will contain a line for any currently active network interfaces, in this case we are setting up the wifi interface so we’re interested in the wlan0 line, find the one you need.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.0.90/24 brd 192.168.0.255 scope global wlan0
       valid_lft forever preferred_lft forever

In the above under the entry labeled “wlan0” the “inet” value is “192.168.0.90/24” and the /24 is the value you’re interested in.

Edit The DHCP Configuration File

Make a backup copy of the configuration file first so in case something goes horribly wrong you can put it back. Something like:

$ sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.orig

Then using nano or your editor of choice open the active file:

$ sudo nano /etc/dhcpcd.conf

The file has lots of stuff at the beginning you’ll want to find the portion towards the end that begins with the comment:

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.245/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

make a copy of that and paste it below the example and make some changes to it.

First edit the comment at the beginning so that it is descriptive of what you’re doing. Maybe add the date and your name so that others looking at this in the far distant future will know what your intent was.

uncomment the “interface” line and if you’re configuring the wlan0 or other interface change the default eth0 to that, If you’re configuring the default ethernet port then leave it after uncommenting.

uncomment the next line “static ip_address=“ and replace the default number with the IP address you wish and the /24 or /16 or whatever you discovered in the above steps.

uncomment the “static routers=“ line and replace the value with the address of your router.

If you do not uncomment the domain_name_servers line it will use the default of the router which is what most people want. If you wish to setup other things instead uncomment that line and set it up as well.

DO NOT uncomment the “static ip6_address” line unless you already know how to setup ipv6. In most circumstances you should let that be configured automatically.

You’ll be left with something like:

# Static Ethernet Address set 3/13/2025 by Tom
interface eth0
static ip_address=192.168.0.245/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

use Ctrl-X to save the changes and exit the editor.

$ sudo reboot

and then reconnect to the server via the new IP address or hostname to verify that it has worked.

/home/e805485/machomeautomation.com/data/pages/tutorials/pistaticip.txt · Last modified: by James Sentman