The “IP” or “Internet Protocol” is the unique network address of a system. It is automatically assigned when a system connects to a network. This automatic assigning is dynamic and could get messy for the users working in a remote environment as they must change the IP address again to reconnect.
The dynamic IP keeps changing every time after logging in. While the static IP remains the same even after disconnection. Users can set the “Static IP” for working in a remote environment effectively while ensuring that their system’s IP remains the same. In Debian 12, users can use multiple methods to set a “Static IP”.
This guide discusses the methods of setting the Static IP Address in Debian 12.
How to Set Up the Static IP Address in Debian 12
To set up and use the static IP address in Debian 12, use either of the following approaches.
- Using Network Interfaces File
- Using the nmcli Command
- Using the nmtui Command
- Using the Network Settings (GUI)
Method 1: Using the Network Interfaces File
The “/etc/network/interface” file allows the users to configure the network interfaces on their system. A Network Interface specifies how the kernel links the software side of the network to the physical side of the network. To set up a static IP address on Debian 12 using the “/etc/network/interfaces”, follow these steps:
Step 1: Create a Backup of the “/etc/network/interfaces” File
Always create a backup file before making changes to the important system files. To back up the “Network Interfaces” file, run the below-mentioned command:
sudo cp /etc/network/interfaces /etc/network/interfaces.bak
Note: If you have incorrectly configured the “/etc/network/interfaces” file, use the “mv /etc/network/interfaces.bak /etc/network/interfaces” to move the backup file to take the place of the misconfigured file.
Step 2: Check for Available IP’s
To set up a static IP, users must ensure the availability of the IPs assigned to the network via the “nmap” utility. To install the “nmap” utility on Debian 12, execute:
sudo apt install nmap -y
Now find your system’s subnet using the below command:
ip addr
After that, view the available IP addresses on your network and note down either one of them. You can only set the static IP address outputted using the below command:
nmap -sP 192.168.18.*
Step 3: Configure the “Network Interfaces” File
Now, bring up the file “Network Interfaces” to configure the system to set/configure the static IP address using the below command:
sudo nano /etc/network/interfaces
Now, use the below format to set the system’s IP to static:
auto enp0s3
iface enp0s3 inet static
address 192.168.18.22
netmask 255.255.255.0
gateway 192.168.18.22
dns-nameservers 8.8.4.4 8.8.8.8
Press the “Ctrl + S” and then “Ctrl + X” to save the changes in the file.
Step 4: Restart the Network Manager
Now, execute the below-mentioned command to restart the Network Manager for the above changes to take effect:
sudo systemctl restart NetworkManager.service
Step 5: Verify the Static IP Address
To verify the static IP address, use the following command:
ip addr
Method 2: Using the nmcli Command
The “nmcli” or “Network manager Command-Line Interface” tool allows the users to manage their system’s network. To set up the static IP address on Debian 12 using the “nmcli” command, follow these steps:
Step 1: View Connection Name
To set up the static IP address, users must find the network connections on their system. For listing all connections and finding the active connection, use the following commands and ensure there is no duplicate connection name:
nmcli connection show
nmcli -t -f NAME c show --active
Here,
- The “nmcli connection show” lists all the connections on the system.
- The “nmcli -t -f NAME c show –active” outputs the active connection.
Step 2: Add a New Connection With a Static IP Address
Now, create a new connection (newcon in this case) and assign a static IP address to it via the following command:
sudo nmcli con add type ethernet con-name 'newcon' ifname enp0s3 ipv4.method manual ipv4.addresses 192.168.18.41/24 gw4 192.168.18.22
Note: In the above command, the gateway matches the IP address as the system is using a direct connection with the network that doesn’t require a router. It uses the “NAT” and you can change the last subset while the first three subsets should remain the same as the IP.
Next, add the DNS IP (Google’s in this case) to the static IP to resolve the domain hostname and be able to connect with the internet using this command:
sudo nmcli con mod newcon ipv4.dns 8.8.4.4,8.8.8.8
Step 3: Activate the Connection
From here, activate the new connection using the below command:
sudo nmcli con up id 'newcon'
Note: If you see the error “connection type is not “loopback”, then you need to discard all changes in the “/etc/network/interfaces” file. Alternatively, you can comment the lines as well using the “#”. The changes take effect when the networking service is restarted. The file’s structure should contain only the following highlighted lines:
Step 4: Test the New Connection
After enabling the new connection, test if it is working using the following command:
ip r
Step 5: Delete a Connection (Optional)
If you want to delete a connection (possibly due to malfunctioning), use the following command and replace the “newcon” with your connection name to delete:
sudo nmcli connection delete newcon
Method 3: Using the nmtui Command
The “nmtui” or “Network Manager Text User Interface” allows the users to manage their network connections using a simple text-based menu. To use it to set the static IP address on Debian 12, follow these steps:
Step 1: Open the “nmtui” Interface
Use the following command to open the “nmtui” interface and select “Edit a connection”:
nmtui
Step 2: Edit the Connection
Now, select the connection you want to edit, and then use the “Edit” option to configure it:
From the following window, set the “IPv4” or “IPv6” to “Manual” and then select the “Show” option using the “Enter” button:
Now, add the IP address and other network connection configurations, as seen below:
To save the changes, scroll down and use the “<OK>”:
Step 3: Restart the Connection
To trigger the changes made using the “nmtui” command, you need to restart the connection. To do that, use the network icon and hit the “gear” icon:
Now, to restart the connection, toggle the highlighted button:
Method 4: Using the Network Settings (GUI)
Users can set up a static IP address on Debian 12 by following these steps:
Step 1: Open Network Settings
Click/tap on the “Network Icon” at the upper right side. From the drop-down, use the “>” icon against the connection and select the “Settings”:
Next, hit the “Gear icon” against your connection, as seen below:
Step 2: Add Static IP Address to the Current Connection
After opening the settings, select “IPv4” or “IPv6”, choose the “Manual” option, and then specify the connection details. Here, add the “Static IP”, “Netmask” and “Gateway (same as the IP)”. To save the changes, hit the “Apply” button:
That’s all for setting up the static IP address on Debian 12.
Final Words
The “Static IP” is the definite IP address associated with a system that remains the same even after rebooting the network/system. To set the “Static IP Address on Debian 12”, use the “Network Interfaces” file or use the “nmcli” or “nmtui” command. Additionally, you can use the “Network Settings” that provide an easy-to-use GUI method to do the same.
This guide has discussed the complete process to set up the “Static IP on Debian 12”.