Operations 7 min read

Mastering IP Configuration on CentOS: Static, Dynamic, IPv4 & IPv6 Guide

This guide explains how to view network interfaces, edit the ifcfg files, enable IPv6 autoconfiguration, set static IPv4/IPv6 addresses, assign temporary addresses, restart the network service on CentOS 6/7, and verify connectivity with ping commands.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering IP Configuration on CentOS: Static, Dynamic, IPv4 & IPv6 Guide

Network Interface Overview

Use ifconfig or ip addr to list interfaces such as eth0 (or ens33 on CentOS 7), lo, and virbr0.

Configuration Files

Network scripts reside in /etc/sysconfig/network-scripts/. Each NIC has a file named ifcfg-INTERFACE (e.g., ifcfg-eth0, ifcfg-lo). Example content for a static IPv4/IPv6 configuration is shown.

# ifcfg-eth0
TYPE=Ethernet
DEVICE=eth0
NAME=eth0
UUID=b4701c26-8ea8-46a5-b738-1d4d0ca5b5a9
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.188
PREFIX=24
GATEWAY=192.168.1.1
DNS1=192.168.0.1
IPV6INIT=yes
IPV6ADDR=2001:250:250:250:250:250:250:222/64
IPV6_DEFAULTGW=2001:250:250:250::1
IPV6_AUTOCONF=no
IPV6_FAILURE_FATAL=no

Enable IPv6 Autoconfiguration

IPv4 uses DHCP by default. To enable IPv6, edit /etc/sysconfig/network and ensure the following lines are present:

NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain

Then set IPV6INIT=yes in the relevant ifcfg-INTERFACE file and restart the network service.

Static IP Configuration

For a permanent IPv4 address, include at least the following keys in ifcfg-INTERFACE:

TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.188
PREFIX=24

(or NETMASK=255.255.255.0)

GATEWAY=192.168.1.1
DNS1=192.168.0.1

For IPv6, add the corresponding entries:

IPV6INIT=yes
IPV6ADDR=2001:250:250:250:250:250:250:222/64
IPV6_DEFAULTGW=2001:250:250:250::1
IPV6_AUTOCONF=no
IPV6_FAILURE_FATAL=no

Temporary (Non‑persistent) Address Assignment

Assign an IPv4 address for the current session:

ifconfig eth0 192.168.5.18 up
ip addr add 192.168.5.18/24 dev eth0

Assign an IPv6 address for the current session:

ifconfig eth0 inet6 add 2001:250:250:250:250:250:250:222/64

These settings disappear after a reboot or when the interface is restarted.

Common Management Commands

Show interfaces: ifconfig or ip addr Restart network service:

CentOS 7: systemctl restart network CentOS 6: service network restart Test connectivity:

IPv4: ping -I eth0 192.168.5.18 IPv6:

ping6 -I eth0 2001:250:250:250:250:250:250:222

Verification

After making changes, verify the configuration with ifconfig (or ip addr) and use the ping commands above to confirm reachability.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

IPv6IPv4Network ConfigurationIP addresssystemdifconfig
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.