Skip to main content

Configuring Network Interfaces

This section will cover ways to configure network interfaces in Linux.

Table of Contents
  • Overview
  • Debian
  • Ubuntu

Overview

This section will cover some basic network configurations for different Linux distributions.

Debian

To set a static IP in Debian, we can edit the /etc/network/interfaces file. We can add the following for a static IP:

 auto <interface>
iface <interface> inet static
address <IP address>/<CIDR>
gateway <gateway IP>

An example:

auto eth0
iface eth0 inet static
address 192.168.1.20/24
gateway 192.168.1.1

linux-config-network-1

To use DHCP, we can use the following instead.

auto <interface>
allow-hotplug <interface>
iface <interface> inet dhcp

An example:

auto ens33
allow-hotplug ens33
iface ens33 inet dhcp

linux-config-network-2

The allow-hotplug <interface> line will allow the interface to be enabled automatically. Once configured, we can restart the service by using the sudo systemctl restart networking command.

To configure DNS, we can edit the /etc/resolv.conf file with the following.

nameserver <IP address>

linux-config-network-3

To add more DNS servers, add more nameserver <IP address>.

Note: Do not use this method if resolvconf is installed on the system.

Ubuntu