How To Find the Subnet Mask in Linux Systems

Whether you're configuring a server or troubleshooting a connection, knowing your subnet mask is key to understanding your network setup. Here are three reliable ways to find it on a Linux system.

Method 1: Using the ip Command

The ip command is a modern replacement for older networking tools and is widely supported across distributions.

Open a terminal window.

Run the command:

ip addr show

Locate your active network interface (typically eth0, wlan0, or similar).

Look for the inet entry, which will show your IP address in CIDR notation (e.g., 192.168.1.6/24).

The number after the slash (/24) represents the subnet mask.

/24 corresponds to 255.255.255.0, meaning the first 24 bits are reserved for the network portion.

If iproute2 is not installed, use your distribution’s package manager to install it:

Distribution Installation Command

Debian-based sudo apt install iproute2

Red Hat-based sudo dnf install iproute

Arch-based sudo pacman -S iproute2

openSUSE-based sudo zypper install iproute2

Method 2: Using the ifconfig Command

Though deprecated in many systems, ifconfig is still available and useful.

Open a terminal window.

Run the command:

ifconfig

Find your active interface. The subnet mask will be listed next to Mask (e.g., Mask:255.255.255.0).

If net-tools is missing, install it using:

Distribution Installation Command

Debian-based sudo apt install net-tools

Red Hat-based sudo dnf install net-tools

Arch-based sudo pacman -S net-tools

openSUSE-based sudo zypper install net-tools

Method 3: Using the nmcli Command

nmcli is the command-line interface for NetworkManager, commonly used in desktop environments.

Open a terminal window.

Run the command:

nmcli dev show

Look for the IP4.ADDRESS entry. The subnet mask will be shown in CIDR format (e.g., 192.168.1.5/24).

To install and activate NetworkManager:

Distribution Installation Command

Debian-based sudo apt install network-manager

Red Hat-based sudo dnf install NetworkManager

Arch-based sudo pacman -S networkmanager

openSUSE-based sudo zypper install NetworkManager

Then start and enable the service:

sudo systemctl start NetworkManager

sudo systemctl enable NetworkManager

With these methods, you can quickly identify your subnet mask and gain better control over your Linux network configuration. Whether you're using a desktop or server environment, these tools make the process simple and accessible.

Post a Comment

Previous Post Next Post

Contact Form