DEV Community

Manoj Kumar Vemula
Manoj Kumar Vemula

Posted on

IP Configuration in Linux: A Beginner-Friendly Guide

For me, Linux used to be much more intimidating at first. But once I understood the basics and started using it regularly, it became straightforward. Assigning an IP address—either automatically via DHCP or manually—is not as hard as it looks. However, troubleshooting can be challenging because Linux provides multiple ways to handle network configurations.


1) The Easiest Way: DHCP (Automatic IP)

This is the simplest way to get an IP address. It automatically assigns network configurations such as IP address, gateway, DNS, and default route.

Command:

sudo dhclient -v eth0
Enter fullscreen mode Exit fullscreen mode
  • dhclient → Requests an IP from the DHCP server
  • -v → Verbose mode (shows packet activity)
  • eth0 → Network interface (may vary: eth0, ens33, wlan0, etc.)

Types of IP Configuration in Linux

There are two main types:

1. DHCP (Automatic)

  • IP is assigned automatically
  • No manual configuration needed

2. Static IP

  • IP is assigned manually
  • Useful for servers or systems requiring a fixed address

Temporary vs Persistent IP Configuration

You can assign IP addresses either temporarily or permanently.

Temporary Static IP (Non-Persistent)

This method stores the IP in RAM. Once the system reboots, the configuration is lost.

sudo ip addr add 192.168.1.225/24 dev eth0
sudo ip route add default via 192.168.1.1
Enter fullscreen mode Exit fullscreen mode

Temporary DNS Configuration:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

Persistent Static IP Configuration

For permanent configuration, Linux uses different tools depending on the distribution.

Since I am using Kali Linux, I prefer nmcli, as Kali uses NetworkManager.

Check Connection Name:

nmcli con show
Enter fullscreen mode Exit fullscreen mode

Static IP Configuration:

sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.225/24
sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli con mod "Wired connection 1" ipv4.method manual
Enter fullscreen mode Exit fullscreen mode

Restart Connection:

sudo nmcli con down "Wired connection 1"
sudo nmcli con up "Wired connection 1"
Enter fullscreen mode Exit fullscreen mode

Switch Back to DHCP (Automatic Mode):

sudo nmcli con mod "Wired connection 1" ipv4.method auto
sudo nmcli con up "Wired connection 1"
Enter fullscreen mode Exit fullscreen mode

Configuration Files in Linux

Different Linux distributions use different configuration systems.

Kali Linux / Debian (NetworkManager)

Managed via:

/etc/NetworkManager/system-connections/
Enter fullscreen mode Exit fullscreen mode

Ubuntu (Netplan)

Modern Ubuntu systems use Netplan.

Configuration File:

/etc/netplan/01-netcfg.yaml
Enter fullscreen mode Exit fullscreen mode

Static IP Example (Netplan):

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.225/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
Enter fullscreen mode Exit fullscreen mode

Apply Changes:

sudo netplan apply
Enter fullscreen mode Exit fullscreen mode

DHCP (Automatic) Configuration:

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: yes
Enter fullscreen mode Exit fullscreen mode

Troubleshooting Commands :

1. Check IP

ip a

2. Check route

ip route

3. Check connection config

nmcli con show
nmcli con show "Wired connection 1"

4. Reset connection (fast fix)

sudo nmcli con delete "Wired connection 1"
sudo systemctl restart NetworkManager

5. Get fresh IP

sudo dhclient -v eth0

6. Test

ping 8.8.8.8
curl google.com

Top comments (0)