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.
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 promiscDisable Promiscuous Mode
ifconfig eth0 -promiscQuery Promiscuous Mode
Use ip or ifconfig to check whether the interface shows the PROMISC flag.
Using ip
ip link show eth0Using ifconfig
ifconfig eth0Programmatic 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, ðreq) != 0) {
perror("ioctl");
close(sock_raw_fd);
exit(-1);
}
ethreq.ifr_flags |= IFF_PROMISC;
if (ioctl(sock_raw_fd, SIOCSIFFLAGS, ðreq) != 0) {
perror("ioctl");
close(sock_raw_fd);
exit(-1);
}Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
