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
-
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
Temporary DNS Configuration:
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
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
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
Restart Connection:
sudo nmcli con down "Wired connection 1"
sudo nmcli con up "Wired connection 1"
Switch Back to DHCP (Automatic Mode):
sudo nmcli con mod "Wired connection 1" ipv4.method auto
sudo nmcli con up "Wired connection 1"
Configuration Files in Linux
Different Linux distributions use different configuration systems.
Kali Linux / Debian (NetworkManager)
Managed via:
/etc/NetworkManager/system-connections/
Ubuntu (Netplan)
Modern Ubuntu systems use Netplan.
Configuration File:
/etc/netplan/01-netcfg.yaml
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]
Apply Changes:
sudo netplan apply
DHCP (Automatic) Configuration:
network:
version: 2
ethernets:
eth0:
dhcp4: yes
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)