If the /etc/network/interfaces
file is missing while configuring linux network, it might be because your Linux distribution uses a different method for network configuration. Here are alternative methods based on various distributions and network managers:
For Systems Using NetworkManager (e.g., Ubuntu 18.04 and newer)
NetworkManager typically uses configuration files in /etc/NetworkManager/
or /etc/netplan/
.
Using Netplan (for Ubuntu 18.04 and newer):
- Netplan configuration files are located in
/etc/netplan/
. List the files in this directory:
ls /etc/netplan/
You will likely see a file with a .yaml
extension, such as 01-netcfg.yaml
or 50-cloud-init.yaml
.
- Edit the YAML configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
- Update the file with the new IP address configuration. For example:
network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.1.10/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
- Apply the changes:
sudo netplan apply
For Red Hat-based Systems Using nmcli
(NetworkManager Command Line Interface)
- List the active connections:
nmcli connection show
- Identify the connection you want to modify (e.g.,
eth0
). - Modify the connection to use a static IP address:
nmcli connection modify eth0 ipv4.addresses 192.168.1.10/24
nmcli connection modify eth0 ipv4.gateway 192.168.1.1
nmcli connection modify eth0 ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection modify eth0 ipv4.method manual
- Bring the connection down and up to apply the changes:
nmcli connection down eth0
nmcli connection up eth0
For Red Hat-based Systems Using ifcfg Files
- Open the specific interface configuration file in a text editor (replace
eth0
with your interface name):
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
- Update the configuration with the new IP address:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
- Save the file and exit the text editor.
- Restart the networking service to apply the changes:
sudo systemctl restart network
Conclusion
The specific method to configure a static IP address permanently depends on your Linux distribution and its version. Use the appropriate method above for your system, whether it’s using Netplan, NetworkManager’s nmcli
, or the traditional ifcfg files in Red Hat-based systems.