Last Updated on 28th April 2023 by peppe8o
Many projects involving desktop-less installations require making it available always with the same IP address. This condition can be achieved by managing networking in Raspberry PI OS Lite settings from the terminal console.
This guide supposes that you are starting from Raspberry PI OS Lite installation.
Raspberry Pi uses dhcpcd daemon to configure TCP/IP across all of its network interfaces. This includes assigning each interface an IP address, setting netmasks, and configuring DNS resolution nameservers.
By default, Raspberry Pi OS attempts to automatically configure all network interfaces by DHCP, falling back to automatic private addresses in the range 169.254.0.0/16 if DHCP fails.
Previous versions of Raspberry Pi OS used the file /etc/network/interfaces for network interface configuration. If an interface is listed in this file, any settings there will take precedence over what is in /etc/dhcpcd.conf.
On Raspberry Pi OS versions with desktop environment installed, a GUI tool called “lxplug-network” is used to allow the user to make changes to the configuration of dhcpcd.
Raspberry PI OS usually lists 2 interfaces (for models WITHOUT ethernet physical interface) or 3 interfaces (all other models):
- wlan0: for WiFi network connection
- eth0: for Ethernet cabled networking connection
- lo: loopback interface used by OS to identify itself (with ip address 127.0.0.1)
You can list all these interfaces and their status with following terminal command:
or with the command:
Correctly Managing Networking Configurations
The correct way to manage networking config is by editing dhcpcd.conf file:
sudo nano /etc/dhcpcd.conf
Default configuration (with no interface settings) uses DHCP to configure both eth0 and wlan0 interfaces.
To make your ethernet interface IP address static, please append these lines to the end of the file, changing Ip addresses with your ones:
interface eth0 static ip_address=192.168.0.10/24 static ip6_address=fd51:42f8:caae:d92e::ff/64 static routers=192.168.0.1 static domain_name_servers=192.168.0.1 220.127.116.11 fd51:42f8:caae:d92e::1
IPv6 info can be omitted, as they are rarely used.
To set static configuration for the WiFi interface, use the same configuration changing “eth0” in “wlan0”.
An interesting option with dhcpcd is using the fallback feature. This feature allows you to use your DHCP service. If (and only if) it fails, then preset a static IP configuration will be used.
For this purpose, we need to add in dhcpcd.conf file following lines (again, use your IP addresses instead of showed ones):
profile static_eth0 static ip_address=192.168.1.23/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 #fallback to static profile on eth0 interface eth0 fallback static_eth0
The first part will define a static profile to be called in specific conditions.
The second part is where the job is done: interface eth0 is defined with the only fallback statement to be used when the DHCP service fails. In this condition, the static_eth0 profile is applied.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?