When Ubuntu initially installs, it automatically detects network interfaces and creates /etc/network/interfaces
. But after manual edits or hardware changes, you might need to reset this configuration to the auto-detected state.
The ifupdown
package handles interface detection. To trigger reconfiguration:
sudo dpkg-reconfigure ifupdown
This will restart network detection but won't fully regenerate the interfaces file.
For a fresh start, first backup your current config:
sudo cp /etc/network/interfaces /etc/network/interfaces.bak
Then use this command sequence:
sudo rm /etc/network/interfaces
sudo apt install --reinstall ifupdown
Modern Ubuntu versions use netplan. To generate traditional interfaces file:
sudo apt install netplan.io
sudo netplan generate
To see what interfaces are available:
ip link show
lshw -class network
After regeneration, you might get something like:
# This file describes the network interfaces available on your system
# and how to activate them.
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
When you first install Ubuntu, it automatically detects your network interfaces and generates the /etc/network/interfaces
file. However, if you later modify your hardware (e.g., add/remove NICs) or want to reset to default, you might need to regenerate this file.
For Ubuntu 17.10 and later, netplan is the preferred network configuration tool. To regenerate configurations:
sudo netplan generate
sudo netplan apply
For older systems using ifupdown, you can try:
sudo ifdown -a
sudo ifup -a
The closest to what you're asking is:
sudo dpkg-reconfigure ifupdown
This will reset the package configuration but won't fully regenerate the interfaces file.
For complete control, you can manually create a basic template:
sudo tee /etc/network/interfaces <
To see what interfaces your system has:
ip link show
# or
ls /sys/class/net
Here's a simple bash script to generate a basic interfaces file:
#!/bin/bash
echo "# Auto-generated interfaces file" | sudo tee /etc/network/interfaces
echo "auto lo" | sudo tee -a /etc/network/interfaces
echo "iface lo inet loopback" | sudo tee -a /etc/network/interfaces
for iface in $(ls /sys/class/net | grep -v lo); do
echo "auto $iface" | sudo tee -a /etc/network/interfaces
echo "iface $iface inet dhcp" | sudo tee -a /etc/network/interfaces
done
- Always back up your current configuration first
- Test changes in a non-production environment
- Some cloud instances use different network managers
- NetworkManager might conflict with ifupdown