A comprehensive guide to managing IP addresses, DNS resolvers, and network interfaces in Linux using both command-line tools and configuration files.
google.com) to IP addresses.ip addr show
Or:
ifconfig # Might require `net-tools` package
ip route show
cat /etc/resolv.conf
ip command:sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip link set eth0 up
ifconfig (deprecated):sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
These changes are temporary and will be lost on reboot.
/etc/network/interfaces):sudo nano /etc/network/interfaces
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 1.1.1.1
Restart service:
sudo systemctl restart networking
sudo nano /etc/resolv.conf
nameserver 8.8.8.8
nameserver 1.1.1.1
⚠️ Changes here may be overwritten by DHCP or resolvconf.
Edit or create the file:
sudo nano /etc/systemd/resolved.conf
Enable DNS settings:
[Resolve]
DNS=8.8.8.8 1.1.1.1
FallbackDNS=9.9.9.9
Then:
sudo systemctl restart systemd-resolved
To make /etc/resolv.conf a symlink to systemd:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
Depending on the system:
sudo systemctl restart networking
sudo systemctl restart NetworkManager
sudo systemctl restart systemd-resolved
ip route
sudo ip route add default via 192.168.1.1 dev eth0
sudo ip route del default
Edit YAML file (example path: /etc/netplan/01-netcfg.yaml)
sudo nano /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
Apply changes:
sudo netplan apply
nmcli con show
nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.100/24
nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 1.1.1.1"
nmcli con mod "Wired connection 1" ipv4.method manual
nmcli con up "Wired connection 1"
nmcli con mod "Wired connection 1" ipv4.method auto
nmcli con up "Wired connection 1"
| Task | Command Example |
|---|---|
| Show IP addresses | ip a or ifconfig |
| Assign IP (temp) | ip addr add 192.168.1.100/24 dev eth0 |
| Set gateway (temp) | ip route add default via 192.168.1.1 |
| Show routing table | ip route |
| Show DNS settings | cat /etc/resolv.conf |
| Change DNS permanently | /etc/systemd/resolved.conf or /etc/network/interfaces |
| Restart networking | systemctl restart networking |
| Apply Netplan | netplan apply |
| Configure with nmcli | nmcli con mod ... |
nslookup google.com
dig google.com
host google.com
ping 8.8.8.8
ping google.com
| Tool | Use |
|---|---|
ip |
View/set interfaces, routes |
nmcli |
NetworkManager CLI tool |
netstat |
View open ports, connections |
ss |
Socket statistics |
dig |
DNS query utility |
resolvectl |
systemd-resolved status |
✅ Mastering IP and DNS configuration ensures you can control Linux networking in cloud, server, and desktop environments efficiently.