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

 

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
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

What Is My Router’s IP Address (Default Gateway)

A router is a device that communicates between the Internet (or public network) and the devices...

CIDR Notation – Explained & Examples

CIDR (Classless Inter-Domain Routing) notation is a compact method for specifying IP addresses...

Disable IPv6 on Linux – Ubuntu, Debian, CentOS

To disable IPv6 on Linux it is required to modify Linux kernel parameters. IPv6 can be temporary...

169.254.0.0/16 – Disable ZEROCONF Route

You may notice that in your routing table you have a route 169.254.0.0/16. It is so called...

What is my Public IP address?

Use one of the following commands to check your public IP address from the Linux command line....