Networking Hub

Back to Networking DevOps Hub
DevOps Hub Networking IP Addressing Guide

Networking Hub — IP Addressing Guide

Debian Logo

Debian Networking Configuration

Configuring Static vs Dynamic IP in Debian

Method 1: Using /etc/network/interfaces File

🔍 Check Current Configuration

First, identify your network interface name:

bash
ip a
# Common names: eth0, ens33, enp0s5, wlp1s0

📌 Setting a STATIC IP Address

Step 1: Edit the interfaces file:

bash
sudo nano /etc/network/interfaces

Step 2: Configure static IP. Change from DHCP to:

bash
# Static IP Configuration
auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

🔄 Setting a DYNAMIC IP Address (DHCP)

Step 1: Edit the interfaces file:

bash
sudo nano /etc/network/interfaces

Step 2: Configure DHCP:

bash
# DHCP Configuration (Dynamic)
auto eth0
iface eth0 inet dhcp

🔁 Restarting Network Interface After Changes

⚠️ Warning: Do NOT run these commands over SSH, as you'll lose connection!

Method 1: Using ifdown and ifup (Recommended)
bash
# Bring interface DOWN
sudo ifdown eth0

# Bring interface UP
sudo ifup eth0

# Verify new IP
ip a show eth0
Method 2: Using systemctl (System-wide restart)
bash
# Restart entire networking service
sudo systemctl restart networking

# Check status
sudo systemctl status networking

# Verify IP address
ip addr show
Method 3: Using ip command (if ifup/ifdown not available)
bash
sudo ip link set eth0 down
sudo ip link set eth0 up
sudo ip link show eth0
Method 4: Restart specific interface with systemd
bash
# For systemd-managed interfaces
sudo systemctl restart ifup@eth0.service

📂 Alternative: Using /etc/network/interfaces.d/ Directory

For better organization, you can separate interface configs:

Step 1: Create interface-specific file:

bash
sudo nano /etc/network/interfaces.d/eth0

Step 2: Add configuration:

bash
# Static IP
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8

Step 3: Modify main interfaces file (ensure source line exists):

bash
source /etc/network/interfaces.d/*

# Loopback
auto lo
iface lo inet loopback

# Reference to external config
auto eth0
✅ Verify Configuration
bash
# Check IP assignment
ip addr show eth0

# Check for active DHCP client
ps aux | grep dhclient

# View DHCP leases (if DHCP)
cat /var/lib/dhcp/dhclient.eth0.leases

# Test connectivity
ping -c 4 8.8.8.8
ping -c 4 google.com