Manually and Automatically Configure Network Interfaces on Linux

Yet another cheat-sheet for configuring network interfaces on Linux servers.

Red Hat, CentOS and Fedora

The main CentOS configuration file normally resides here:
/etc/sysconfig/network-scripts/ifcfg-eth0

Configure DHCP

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR="01:23:45:67:89:00"
NM_CONTROLLED=yes
TYPE=Ethernet

Configure Static IP

DEVICE=eth0
BOOTPROTO=static
IPADDR=10.1.1.2
NETMASK=255.255.255.0
GATEWAY=10.1.1.1
ONBOOT=yes
HWADDR="01:23:45:67:89:00"
NM_CONTROLLED=yes
TYPE=Ethernet

Debian, Ubuntu

The main Debian configuration file normally resides here:
/etc/network/interfaces

Configure DHCP

# start on boot
auto eth0
iface eth0 inet dhcp

Configure Static IP

# start on boot
auto eth0
iface eth0 inet static
 address 10.1.1.2
 netmask 255.255.255.0
 gateway 10.1.1.1
 # dns-* options are implemented by the resolvconf package, if installed
 dns-nameservers 8.8.8.8
 dns-nameservers 8.8.4.4

DNS

Nameserver configuration normally resides here: /etc/resolv.conf

Example

nameserver 8.8.8.8
nameserver 8.8.4.4

Leave a Reply

Your email address will not be published. Required fields are marked *