Manual Static IP Configuration for CentOS 7 Network Interfaces
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 portBridge— software layer-2 switch connecting multiple interfacesBond— kernel-level link aggregation for failover or throughputTeam— user-space link aggregation managed byteamdVlan— 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=24andNETMASK=255.255.255.0are 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