Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Manual Static IP Configuration for CentOS 7 Network Interfaces

Notes 1

Identifying Active Network Hardware

List available interfaces and their current state:

nmcli device status

Typical output includes the local loopback (lo at 127.0.0.1/8), physical adapters such as ens192 or enp0s3, and virtual devices like Docker bridges or VLAN sub-interfaces. Physical adapters hendle external traffic, whereas lo is strictly for internal host communication and should remain untouched.

Gathering Existing Network Parameters

Before editing any profile, record the current settings you intend to keep or replace:

ip addr show ens192

Locate the inet entry. An address shown as 198.51.100.75/24 uses a prefix length of 24. To derive the dotted-decimal netmask, count the network bits: /24 corresponds to 255.255.255.0 because the first 24 of 32 bits are set to 1. The remaining bits represent the host portion. Usable host address are calculated as 2^(host bits) − 2; for /24 that yields 254 addresses.

Retrieve the default gateway:

ip route | grep default

Inspect configured DNS resolvers:

cat /etc/resolv.conf

Interface Types in Profile Files

CentOS 7 connection profiles use the TYPE directive to declare the link-layer technology. Frequently used values include:

  • Ethernet — standard physical wired port
  • Bridge — software layer-2 switch connecting multiple interfaces
  • Bond — kernel-level link aggregation for failover or throughput
  • Team — user-space link aggregation managed by teamd
  • Vlan — 802.1Q tagged virtual interface

Editing the Connection Profile

Configuration files live in /etc/sysconfig/network-scripts/ and are named ifcfg-<interface>. Create or modify the file for the target adapter:

sudo vi /etc/sysconfig/network-scripts/ifcfg-ens192

A typical static assignment for a standard Ethernet port:

TYPE=Ethernet
BOOTPROTO=static
DEVICE=ens192
NAME=ens192
ONBOOT=yes

IPADDR=198.51.100.75
PREFIX=24
GATEWAY=198.51.100.1
DNS1=1.1.1.1
DNS2=8.8.8.8

PREFIX=24 and NETMASK=255.255.255.0 are functionally equivalent.

For an aggregated bond0 interface in active-backup mode:

TYPE=Bond
BOOTPROTO=static
DEVICE=bond0
NAME=bond0
ONBOOT=yes
BONDING_OPTS="mode=active-backup miimon=100"

IPADDR=198.51.100.50
PREFIX=24
GATEWAY=198.51.100.1
DNS1=1.1.1.1

For a VLAN sub-interface ens192.20 on VLAN ID 20:

TYPE=Ethernet
BOOTPROTO=static
DEVICE=ens192.20
NAME=ens192.20
ONBOOT=yes
VLAN=yes

IPADDR=203.0.113.20
PREFIX=24
GATEWAY=203.0.113.1

For a software bridge br0:

TYPE=Bridge
BOOTPROTO=static
DEVICE=br0
NAME=br0
ONBOOT=yes

IPADDR=198.51.100.200
PREFIX=24
GATEWAY=198.51.100.1
DNS1=1.1.1.1

Applying and Validating the Configuration

Restart the network service to load the updated profile:

sudo systemctl restart network

Confirm addressing and routing:

ip addr show ens192
ip route
ping -c 4 1.1.1.1

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.