IP Address Management on Redhat and Ubuntu Linux

Show IP Address

# Show all interfaces
ip a

# Short/brief output (clean one-liner per interface)
ip -br a

# Specific interface
ip a show ens192

# IPv4 only
ip -4 a

# IPv6 only
ip -6 a

# Show routing table
ip r

# Show interface state (up/down, MAC, MTU)
ip link show

nmcli alternatives (RHEL):

# All connections
nmcli con show

# Full device details including IP, DNS, gateway
nmcli dev show

# Specific interface
nmcli dev show ens192

# Brief device status
nmcli dev status

# Filtered output – IP and gateway only
nmcli -f IP4.ADDRESS,IP4.GATEWAY,IP4.DNS con show ens192

Sample ip -br a output:

lo               UNKNOWN    127.0.0.1/8
ens192           UP         192.168.1.100/24
ens224           UP         10.10.10.5/24

⚠️ ifconfig is deprecated – use ip and nmcli on modern Linux.


Configure Static IP – Ubuntu (Netplan)

Config files are located at /etc/netplan/. The default file is typically:

/etc/netplan/01-netcfg.yaml

Static IP:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens35:
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.20.1/24
      routes:
        - to: default
          via: 192.168.20.21
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]

⚠️ The gateway4 key is deprecated in newer Ubuntu releases. Use routes: with to: default instead.

DHCP:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens35:
      dhcp4: yes
      dhcp6: yes

Apply changes:

sudo netplan apply

# Test before applying (auto-reverts after 120s if not confirmed)
sudo netplan try

Configure Static IP – RHEL / Rocky Linux

Using nmcli (recommended)

# List all adapters
nmcli con show
nmcli device status

# Set static IP
sudo nmcli con mod ens192 ipv4.addresses 192.168.1.100/24
sudo nmcli con mod ens192 ipv4.gateway 192.168.1.1
sudo nmcli con mod ens192 ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con mod ens192 ipv4.method manual

# Bring interface up
sudo nmcli con up ens192

Set DHCP:

sudo nmcli con mod ens192 ipv4.method auto
sudo nmcli con mod ens192 ipv4.addresses ""
sudo nmcli con mod ens192 ipv4.gateway ""
sudo nmcli con mod ens192 ipv4.dns ""
sudo nmcli con up ens192

Reload config (if editing files manually):

sudo nmcli con reload
sudo nmcli con up ens192

Using ifcfg files (RHEL 7/8 – deprecated in RHEL 9)

File location: /etc/sysconfig/network-scripts/ifcfg-ens192

TYPE=Ethernet
BOOTPROTO=none
NAME=ens192
DEVICE=ens192
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
# Restart networking
systemctl restart NetworkManager

⚠️ ifcfg support is deprecated in RHEL 9. Migrate to keyfiles or use nmcli.


RHEL 9 – NetworkManager Keyfiles

Default config location in RHEL 9:

/etc/NetworkManager/system-connections/ens192.nmconnection
# View config
cat /etc/NetworkManager/system-connections/ens192.nmconnection

# List all connection files
ls /etc/NetworkManager/system-connections/

Example keyfile:

[connection]
id=ens192
type=ethernet
interface-name=ens192

[ethernet]
auto-negotiate=true

[ipv4]
method=manual
addresses=192.168.1.100/24
gateway=192.168.1.1
dns=8.8.8.8;8.8.4.4;

[ipv6]
method=disabled
# After editing the file manually, reload and apply
sudo nmcli con reload
sudo nmcli con up ens192

💡 Files must have permissions 600 – NetworkManager will ignore world-readable keyfiles.

chmod 600 /etc/NetworkManager/system-connections/ens192.nmconnection

Secondary IP Address

# Add secondary IP to an interface
nmcli con mod ens224 +ipv4.addresses "172.16.99.103/24"
nmcli con up ens224

# Remove a secondary IP
nmcli con mod ens224 -ipv4.addresses "172.16.99.103/24"
nmcli con up ens224

# View all IPs on interface
ip a show ens224

Enable / Disable Interfaces

# Bring interface down / up via nmcli (preferred)
nmcli connection down ens224
nmcli connection up ens224

# Legacy ifup / ifdown (RHEL 7/8)
ifup ens160
ifdown ens160

# Using ip command (temporary, no persistent state)
sudo ip link set ens192 down
sudo ip link set ens192 up

Check interface status:

nmcli con show

# Example output:
# NAME                UUID                                  TYPE      DEVICE
# ens160              9ecab589-8a09-3e57-8895-a0d118b39be0  ethernet  ens160
# Wired connection 1  f945af43-4358-34ad-91ce-b50c8c0d6444  ethernet  ens224

nmcli device status

# Example output:
# DEVICE  TYPE      STATE        CONNECTION
# ens160  ethernet  connected    ens160
# ens224  ethernet  disconnected --

💡 If the connection name contains spaces, escape it:

nmcli connection down "Wired connection 1"

Routing

# Show routing table
ip route show
ip r

# Add a static route (temporary)
sudo ip route add 192.168.11.0/24 via 192.168.11.253

# Add a static route (legacy)
route add -net 192.168.11.0 netmask 255.255.255.0 gw 192.168.11.253

# Delete a route
sudo ip route del 192.168.11.0/24

# Add default gateway
sudo ip route add default via 192.168.1.1

Persistent static route via nmcli:

nmcli con mod ens192 +ipv4.routes "192.168.11.0/24 192.168.11.253"
nmcli con up ens192

NIC Statistics & ethtool

# Install ethtool
yum install -y ethtool        # RHEL/Rocky
apt install -y ethtool        # Ubuntu/Debian

# View NIC stats (RX/TX counters, errors)
ethtool -S ens224

# Check speed, duplex, auto-negotiation
ethtool ens224

# Check auto-negotiation, RX and TX pause frames
ethtool -a ens224

# Change speed (temporary)
ethtool -s ens224 speed 1000 duplex full
ip link set ens224 up

# Disable / enable auto-negotiation
ethtool -s ens224 autoneg off
ethtool -s ens224 autoneg on

# Check driver and firmware info
ethtool -i ens224

# Show offload settings
ethtool -k ens224

Make ethtool settings persistent (RHEL 7/8 ifcfg):

vi /etc/sysconfig/network-scripts/ifcfg-ens224
ETHTOOL_OPTS="speed 1000 duplex full autoneg off"

Make ethtool settings persistent (RHEL 9 – dispatcher script):

cat /etc/NetworkManager/dispatcher.d/99-ethtool-ens224
#!/bin/bash
[ "$1" = "ens224" ] && [ "$2" = "up" ] && ethtool -s ens224 speed 1000 duplex full autoneg off
chmod +x /etc/NetworkManager/dispatcher.d/99-ethtool-ens224

Port & Connection Statistics

# Show all connections
netstat -a | more

# Show listening TCP ports with PID
netstat -ltnp

# Check specific port (e.g. port 80)
netstat -ltnp | grep -w ':80'

# Show routing table
netstat -nr

# Display NIC statistics
netstat -ai

# Show all active TCP connections
netstat -ant

# Show all listening services (TCP + UDP)
netstat -pnltu

# Modern alternative to netstat (ss)
ss -tulnp                     # All listening ports
ss -tnp                       # Active TCP connections
ss -tnp | grep :443           # Filter by port

# Find which process is using a port
fuser 80/tcp

# Scan all open ports on localhost (slow)
sudo nmap -n -PN -sT -sU -p- localhost

💡 netstat is deprecated – prefer ss on modern Linux (RHEL 7+).


Subnet Ping Scanner Scripts

Method 1 – grep Unreachable

#!/bin/ksh
# Usage: ./ping_scan.sh 192.168.1
Subnet=$1
for i in `seq 1 255`;
do
  if ping -c1 $Subnet.$i | grep -q 'Unreachable' >/dev/null 2>&1
  then
    echo $Subnet.$i -- Unreachable
  else
    echo $Subnet.$i -- Reachable
  fi
done

Method 2 – Check packet loss percentage

#!/bin/ksh
# Usage: ./ping_scan.sh 192.168.1
Subnet=$1
for i in `seq 1 255`;
do
  if ping -c1 $Subnet.$i | grep 'transmitted' | awk '{print $6}' | cut -d '%' -f1 | grep -q "100" >/dev/null 2>&1
  then
    echo $Subnet.$i -- Unreachable
  else
    echo $Subnet.$i -- Reachable
  fi
done

Method 3 – fping (faster, parallel)

# Install fping
yum install -y fping        # RHEL/Rocky
apt install -y fping        # Ubuntu

# Scan entire subnet
fping -a -g 192.168.1.0/24 2>/dev/null

# Show both alive and unreachable
fping -a -u -g 192.168.1.0/24

Quick Reference

TaskCommand
Show all IPsip -br a
Show routing tableip r
Show connectionsnmcli con show
Reload NM confignmcli con reload
Restart interfacenmcli con down ens192 && nmcli con up ens192
Check port usagess -tulnp
NIC statsethtool -S ens192
Scan subnetfping -a -g 192.168.1.0/24
(Visited 8 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.