Configuring Network Settings in Linux

IP Address Classification

IPv4 addresses are categorized into five classes (A through E), although D (multicast) and E (experimental) are rarely configured on standard hosts.

  • Class A: The first octet represents the network (1-127). The loopback address consumes 127.0.0.0/8, leaving 126 valid networks. Each network supports 2^24 - 2 hosts. Default subnet mask: 255.0.0.0 (/8). Private range: 10.0.0.0/8.
  • Class B: The first two octets represent the network (128-191). Provides 2^14 networks, each supporting 2^16 - 2 hosts. Default subnet mask: 255.255.0.0 (/16). Private range: 172.16.0.0/12.
  • Class C: The first three octets represent the network (192-223). Provides 2^21 networks, each supporting 2^8 - 2 hosts. Default subnet mask: 255.255.255.0 (/24).

Within any IP range, a host portion of all zeros denotes the network address, while a host portion of all ones represents the broadcast address.

Network Interface Naming Conventions

Traditional Linux kernels assigned sequential names to interfaces, such as eth0 for Ethernet or ppp0 for point-to-point protocols.

Modern distributions (e.g., CentOS 7+) utilize predictable naming schemes derived from firmware and topology:

  • eno1: Onboard device indexed by firmware.
  • ens1: PCI-E hotplug slot indexed by firmware.
  • enp2s0: Physical location topology (bus 2, slot 0).
  • enx78e7d1ea4632: MAC address-based naming.

The prefix changes based on media type: en (Ethernet), wl (WLAN), ww (WWAN).

Dynamic Configuration via iproute2

Managing Links

The ip link command manages device state and properties.

# Deactivate an interface
ip link set enp3s0 down

# Activate an interface
ip link set enp3s0 up

# Disable multicast
ip link set enp3s0 multicast off

# Rename an interface (requires link down state)
ip link set enp3s0 name wan0

Managing Addresses

The ip addr command handles IP assignment and removal.

# Add a primary IP
ip addr add 192.168.10.50/24 dev enp3s0

# Add a secondary aliased IP
ip addr add 192.168.10.55/24 dev enp3s0 label enp3s0:1

# Remove a specific IP
ip addr del 192.168.10.55/24 dev enp3s0:1

# Flush all IPs from an interface
ip addr flush dev enp3s0

Routing Tables

The ip route command manipulates the kernel routing table.

# Add a default gateway
ip route add default via 192.168.10.1

# Add a network route
ip route add 10.50.0.0/16 via 192.168.10.1 dev enp3s0

# Add a host route
ip route add 10.50.2.5 via 192.168.10.1 dev enp3s0

# Delete a route
ip route del 10.50.0.0/16

# Query the route to a destination
ip route get 10.50.2.5

Network Namespaces

Network namespaces isolate network stacks for virtualization.

# Create a namespace
ip netns add isolated_ns

# Move an interface into the namespace
ip link set enp3s0 netns isolated_ns

# Execute a command inside the namespace
ip netns exec isolated_ns ip link show

# Remove the namespace
ip netns del isolated_ns

Legacy net-tools Utilities

Interface and Address Management

The ifconfig tool applies addresses immediately but changes are lost on reboot.

# Assign IP and mask
ifconfig enp3s0 192.168.10.50 netmask 255.255.255.0 up

Routing Management

# View routing table numerically
route -n

# Add default gateway
route add default gw 192.168.10.1 dev enp3s0

# Add network route
route add -net 10.50.0.0/8 gw 192.168.10.1 dev enp3s0

# Add host route
route add -host 10.50.2.5 gw 192.168.10.1

# Delete routes
route del -net 10.50.0.0/8
route del -host 10.50.2.5

Network Statistics

The netstat command displays connections, routing, and interface stats.

# Display routing table
netstat -rn

# Display all listening TCP sockets with process info
netstat -tnlp

# Display all TCP sockets numerically
netstat -tan

# Interface statistics
netstat -i
netstat -Ienp3s0

Interface Activation Scripts

Commands ifup and ifdown read persistent definitions from /etc/sysconfig/network-scripts/ifcfg-* to toggle interface states.

Socket Statistics with ss

The ss command provides faster, more detailed socket information than netstat, including advanced filtering.

# List all listening TCP sockets with processes
ss -tnlp

# List all TCP sockets
ss -tan

# Filter by established state
ss -tan state established

# Filter by specific port
ss -tan '( dport = :22 or sport = :22 )'

System Identity Configuration

To inspect or modify the hostname:

# Temporary change
hostname node-alpha

# Permanent change (CentOS 7+)
hostnamectl set-hostname node-alpha.internal
hostnamectl status

On older systems, the persistent hostname is defined in /etc/sysconfig/network via the HOSTNAME variable.

Domain Name Resolution

Resolver configuration is stored in /etc/resolv.conf.

nameserver 8.8.8.8
nameserver 8.8.4.4

Verify DNS resolution using utilities like dig or nslookup (installable via yum install bind-utils).

dig -t A www.example.com

Persistent Network Configuration

Interface Definitions

Permanent interface parameters are defined in /etc/sysconfig/network-scripts/ifcfg-<INTERFACE>. Graphical tools like nmtui or CLI tools like nmcli can also manipulate these files.

DEVICE=enp3s0
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.10.50
PREFIX=24
GATEWAY=192.168.10.1
DNS1=8.8.8.8
DOMAIN=internal

Static Routes

Persistent routes are stored in /etc/sysconfig/network-scripts/route-<INTERFACE>. Two formats are supported, but cannot be mixed within the same file.

Format 1: Inline notation

10.50.0.0/16 via 192.168.10.1

Format 2: Parameter notation

ADDRESS0=10.50.0.0
NETMASK0=255.255.0.0
GATEWAY0=192.168.10.1

Interface Aliases

Multiple IPs can be bound to a single physical interface using aliases. Aliases cannot request DHCP. To configure an alias, copy the primary interface configuration file and modify the DEVICE directive to include the alias index, remove the UUID, and set the secondary IP.

# File: ifcfg-enp3s0:1
DEVICE=enp3s0:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.10.55
PREFIX=24

After modifying persistent configuration files, apply the changes by restarting the network service.

# CentOS 6
service network restart

# CentOS 7
systemctl restart network.service

Tags: Linux networking iproute2 System Administration TCP/IP

Posted on Sun, 26 Jul 2026 16:16:19 +0000 by George Botley