Configuring Network on CentOS/RHEL — Basic Configuration

Interface configuration files control the software interfaces for individual network devices.

As the system boots, it uses these files to determine what interfaces to bring up and how to configure them.

These files are usually named ifcfg-<name>, where <name> refers to the name of the device that the configuration file controls.

Because each device has its own configuration file, an administrator can control how each interface functions individually.

Configure Network Interface Settings

You can configure network interface by editing configuration files stored in /etc/sysconfig/network-scripts/ directory.

Lets configure the first network interface eth0. Edit the interface configuration file.

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Append/Modify as follows:

For a system using a Static IP Address

DEVICE="eth0"
BOOTPROTO="none"
ONBOOT="yes"
IPADDR="192.168.1.15"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"

For a system using a DHCP

DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"

Parameter

Description

DEVICE=<name> Name of the physical device
BOOTPROTO=<none|bootp|dhco> Protocol to use.
none – No boot-time protocol should be used
bootp – The BOOTP protocol should be used
dhcp – The DHCP protocol should be used
ONBOOT=<yes|no> Should the device be activated at boot-time
IPADDR=<address> IP address
GATEWAY=<address> Gateway IP address
NETMASK=<mask> Netmask value

Configure Networking

Edit the main network configuration file:

# vi /etc/sysconfig/network

Append the following settings:

NETWORKING="yes"
HOSTNAME="Your.Server.Name"

Restart networking:

# /etc/init.d/network restart

If the modifying of the file /etc/sysconfig/network is not needed, then you can restart only the interface:

# ifdown eth0 && ifup eth0

Configure DNS settings

Edit ‘resolv.conf’ file:

# vi /etc/resolv.conf

Append your DNS servers:

nameserver 192.168.1.2
nameserver 192.168.1.3

If you don’t have private DNS servers, you can pick them from a list of Free Fast Public DNS Servers

Test Your Settings

Check if the Gateway is reachable:

# ping 192.168.1.1

Check if the Public IPs are reachable:

# ping 8.8.8.8

Check if DNS works:

# nslookup google.com

Leave a Reply