Progress: 0/62 (0%)

βš™οΈ Editing Network Configuration Files

Editing Network Configuration Files

When you want to change your network settings permanentlyβ€”like IP address, DNS, or gatewayβ€”you edit configuration files. This is deeper than just running ifconfig or ip a, which are temporary changes.

Locations of Config Files

The location depends on your Linux distribution:

1. Debian/Ubuntu:

  • Main file: /etc/network/interfaces (older systems)
  • Or /etc/netplan/*.yaml (modern Ubuntu versions)

2. RedHat/CentOS/Fedora:

  • Main files: /etc/sysconfig/network-scripts/ifcfg-<interface>
  • Example: /etc/sysconfig/network-scripts/ifcfg-eth0

3. DNS settings:

  • /etc/resolv.conf β†’ contains DNS server addresses

Editing the Files

1. Debian/Ubuntu (Netplan example):

πŸ“Œ Example:
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.1.50/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Apply changes:

sudo netplan apply

2. RedHat/CentOS (ifcfg example):

πŸ“Œ Example:
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.50
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4

Restart network service to apply:

sudo systemctl restart network

Important Notes

Always backup the original file before editing:

sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak

Small syntax mistakes can break network connectivity, so double-check formatting (especially YAML indentation). After changes, always test connectivity (ping, ip a) to confirm.

Real-life analogy

Think of these files as the "blueprints" of your house's network β€” who lives where, which door connects to which street, and which mailbox (DNS) to use. Editing config files is like rewiring your house β€” if done wrong, doors may not open, or mail won't arrive. But done correctly, your house is fully optimized for the neighborhood.