How To Set a Static IP Address for Your Device in Linux Systems


Assigning a static IP address in Linux ensures consistent network configuration, especially for servers, printers, or devices requiring fixed access. This guide walks you through three reliable methods: graphical interface, command line (nmcli), and text-based UI (nmtui).

Method 1: Using the Graphical Interface

This method is ideal for desktop users who prefer a visual approach.

  • Open the Settings application from your system menu.
  • Navigate to the Network tab.
  • Locate your active network connection and click the gear icon beside it.
  • Switch to the IPv4 tab.
  • Change the Method from “Automatic (DHCP)” to “Manual”.
  • Enter the following details:

  1. IP Address: e.g., 192.168.1.103
  2. Netmask: typically 255.255.255.0
  3. Gateway: your router’s IP, e.g., 192.168.1.1
  4. DNS Servers: e.g., 1.1.1.1, 1.0.0.1

  • Save your changes and restart your device if necessary.

Method 2: Using NetworkManager with nmcli

NetworkManager is a powerful tool available by default in many Linux distributions like Debian, Fedora, openSUSE, and Manjaro.

Step 1: Identify Your Network Interface

Open a terminal and run:

nmcli device status

Look for your active interface name:

  • Ethernet: eth0, eno1, etc.
  • Wi-Fi: wlan0, wlp2s0, etc.

Step 2: Modify the Connection

Replace "Wired connection 1" with your actual connection name:

sudo nmcli connection modify "Wired connection 1" ipv4.addresses "192.168.1.103/24"

sudo nmcli connection modify "Wired connection 1" ipv4.gateway "192.168.1.1"

sudo nmcli connection modify "Wired connection 1" ipv4.dns "1.1.1.1 1.0.0.1"

sudo nmcli connection modify "Wired connection 1" ipv4.method "manual"

sudo nmcli connection modify "Wired connection 1" connection.autoconnect "yes"

Step 3: Apply the Changes

sudo nmcli connection down "Wired connection 1"

sudo nmcli connection up "Wired connection 1"

If needed, restart NetworkManager:

sudo systemctl restart NetworkManager

Method 3: Using NetworkManager with nmtui

nmtui offers a text-based interactive interface, useful for minimal environments.

Step 1: Launch nmtui

nmtui

Step 2: Edit the Connection

  • Select Edit a connection.
  • Choose your Ethernet or Wi-Fi profile.
  • Set IPv4 Configuration Method to Manual.
  • Enter your IP address, subnet mask, gateway, and DNS servers.
  • Save and exit.

Step 3: Activate the Connection

  • Select Activate a connection.
  • Choose the updated profile to apply changes.

Installing NetworkManager (if missing)

Use your distribution’s package manager:

Debian/Ubuntu:

sudo apt install network-manager

Fedora/Red Hat:

sudo dnf install NetworkManager

Arch Linux:

sudo pacman -S networkmanager

openSUSE:

sudo zypper install NetworkManager

Enable and start the service:

sudo systemctl start NetworkManager

sudo systemctl enable NetworkManager

Setting a static IP in Linux is straightforward once you choose the right method for your environment. Whether you prefer GUI tools or terminal commands, these steps ensure reliable network configuration across distributions.

Post a Comment

Previous Post Next Post

Contact Form