Fundamentals 4 min read

Enable and Use Promiscuous Mode on Linux: Commands and C Code

This guide explains what network‑card promiscuous (promisc) mode is, why it matters for receiving packets across different subnets, and provides step‑by‑step Linux commands and a C program example to enable, disable, and verify the mode on an interface.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Enable and Use Promiscuous Mode on Linux: Commands and C Code

Introduction

During development a board needed to receive multicast packets from a customer module that resides in a different IP subnet. By default the NIC drops such packets, so the article explains how to capture traffic from other subnets by enabling the network‑card promiscuous mode.

Promiscuous Mode

Promiscuous mode (also called "promisc" or listening mode) allows a host to accept every Ethernet frame that passes the NIC, regardless of the destination MAC address. In normal (non‑promiscuous) mode the NIC only receives frames addressed to its own MAC, plus broadcast and multicast frames.

NIC Working Modes

Broadcast mode

Multicast mode

Unicast mode

Promiscuous mode

Setting Promiscuous Mode on Linux

Enable Promiscuous Mode

ifconfig eth0 promisc

Disable Promiscuous Mode

ifconfig eth0 -promisc

Query Promiscuous Mode

Use ip or ifconfig to check whether the interface shows the PROMISC flag.

Using ip

ip link show eth0
ip link output
ip link output

Using ifconfig

ifconfig eth0
ifconfig output
ifconfig output

Programmatic Enabling in C

The following C snippet demonstrates how to enable promiscuous mode programmatically using ioctl calls.

struct ifreq ethreq;
strncpy(ethreq.ifr_name, "eth0", IFNAMSIZ);
if (ioctl(sock_raw_fd, SIOCGIFFLAGS, &ethreq) != 0) {
    perror("ioctl");
    close(sock_raw_fd);
    exit(-1);
}
ethreq.ifr_flags |= IFF_PROMISC;
if (ioctl(sock_raw_fd, SIOCSIFFLAGS, &ethreq) != 0) {
    perror("ioctl");
    close(sock_raw_fd);
    exit(-1);
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxC programmingipifconfigPromiscuous Mode
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.