netdevice(7)

๐Ÿ‘‘ netdevice(7) ๐Ÿ‘‘

okay so bestie, this one comes straight out of the Miscellaneous Information Manual, and it is literally the page about talking to Linux network devices at the lowest level. no cap. ๐Ÿฆ‹


๐ŸŒธ NAME ๐ŸŒธ

netdevice โ€” low-level access to Linux network devices ๐Ÿ’…


โœจ SYNOPSIS โœจ

#include <sys/ioctl.h>
#include <net/if.h>

๐Ÿซถ DESCRIPTION ๐Ÿซถ

so like, this man page describes the sockets interface that gets used to configure network devices. that's the whole vibe. ๐ŸŽ€

Linux supports some standard ioctls to configure network devices. the way that they work is: you can use them on any socket's file descriptor, regardless of the family or type. bestie they do not care. ๐Ÿ™ˆ Most of them pass an ifreq structure, and here it is in all its glory:

struct ifreq {
    char ifr_name[IFNAMSIZ];  /* Interface name */
    union {
        struct sockaddr ifr_addr;
        struct sockaddr ifr_dstaddr;
        struct sockaddr ifr_broadaddr;
        struct sockaddr ifr_netmask;
        struct sockaddr ifr_hwaddr;
        short           ifr_flags;
        int             ifr_ifindex;
        int             ifr_metric;
        int             ifr_mtu;
        struct ifmap    ifr_map;
        char            ifr_slave[IFNAMSIZ];
        char            ifr_newname[IFNAMSIZ];
        char           *ifr_data;
    };
};

AF_INET6 is the exception, she's different ๐Ÿ’œ โ€” she passes an in6_ifreq structure instead:

struct in6_ifreq {
    struct in6_addr     ifr6_addr;
    u32                 ifr6_prefixlen;
    int                 ifr6_ifindex;  /* Interface index */
};

Normally you (the user) say which device you wanna mess with by setting ifr_name to the name of the interface, or ifr6_ifindex to the index of the interface. and all the other members of the structure? they may share memory. iconic behaviour honestly. โœจ

๐Ÿ’… Ioctls ๐Ÿ’…

quick heads up: if an ioctl is marked as privileged, then using it requires an effective user ID of 0 or the CAP_NET_ADMIN capability. if you don't have that, EPERM gets returned. sorry bestie. ๐Ÿ˜ญ

SIOCGIFNAME

Given the ifr_ifindex, return the name of the interface in ifr_name. this is the only ioctl which returns its result in ifr_name. main character energy, honestly. ๐Ÿ‘‘

SIOCGIFINDEX

Retrieve the interface index of the interface into ifr_ifindex.

SIOCGIFFLAGS, SIOCSIFFLAGS

Get or set the active flag word of the device. ifr_flags contains a bit mask of the following values:

Device flags:

  • IFF_UP โ€” Interface is running.
  • IFF_BROADCAST โ€” Valid broadcast address set.
  • IFF_DEBUG โ€” Internal debugging flag.
  • IFF_LOOPBACK โ€” Interface is a loopback interface.
  • IFF_POINTOPOINT โ€” Interface is a point-to-point link.
  • IFF_RUNNING โ€” Resources allocated.
  • IFF_NOARP โ€” No arp protocol, L2 destination address not set.
  • IFF_PROMISC โ€” Interface is in promiscuous mode.
  • IFF_NOTRAILERS โ€” Avoid use of trailers.
  • IFF_ALLMULTI โ€” Receive all multicast packets.
  • IFF_MASTER โ€” Master of a load balancing bundle.
  • IFF_SLAVE โ€” Slave of a load balancing bundle.
  • IFF_MULTICAST โ€” Supports multicast
  • IFF_PORTSEL โ€” Is able to select media type via ifmap.
  • IFF_AUTOMEDIA โ€” Auto media selection active.
  • IFF_DYNAMIC โ€” The addresses are lost when the interface goes down.
  • IFF_LOWER_UP โ€” Driver signals L1 up (since Linux 2.6.17)
  • IFF_DORMANT โ€” Driver signals dormant (since Linux 2.6.17)
  • IFF_ECHO โ€” Echo sent packets (since Linux 2.6.25)

Setting the active flag word is a privileged operation, but any process may read it. read-only girlies, you're fine. ๐ŸŒธ

SIOCGIFPFLAGS, SIOCSIFPFLAGS

Get or set extended (private) flags for the device. ifr_flags contains a bit mask of the following values:

Private flags:

  • IFF_802_1Q_VLAN โ€” Interface is 802.1Q VLAN device.
  • IFF_EBRIDGE โ€” Interface is Ethernet bridging device.
  • IFF_SLAVE_INACTIVE โ€” Interface is inactive bonding slave.
  • IFF_MASTER_8023AD โ€” Interface is 802.3ad bonding master.
  • IFF_MASTER_ALB โ€” Interface is balanced-alb bonding master.
  • IFF_BONDING โ€” Interface is a bonding master or slave.
  • IFF_SLAVE_NEEDARP โ€” Interface needs ARPs for validation.
  • IFF_ISATAP โ€” Interface is RFC4214 ISATAP interface.

Setting the extended (private) interface flags is a privileged operation.

SIOCGIFADDR, SIOCSIFADDR, SIOCDIFADDR

Get, set, or delete the address of the device using ifr_addr, or ifr6_addr with ifr6_prefixlen. setting or deleting the interface address is a privileged operation. for compatibility: SIOCGIFADDR returns only AF_INET addresses, SIOCSIFADDR accepts AF_INET and AF_INET6 addresses, and SIOCDIFADDR deletes only AF_INET6 addresses. an AF_INET address can be deleted by setting it to zero via SIOCSIFADDR. the way that's so specific of them ๐Ÿ˜ญ

SIOCGIFDSTADDR, SIOCSIFDSTADDR

Get or set the destination address of a point-to-point device using ifr_dstaddr. for compatibility, only AF_INET addresses are accepted or returned. setting the destination address is a privileged operation.

SIOCGIFBRDADDR, SIOCSIFBRDADDR

Get or set the broadcast address for a device using ifr_brdaddr. for compatibility, only AF_INET addresses are accepted or returned. setting the broadcast address is a privileged operation.

SIOCGIFNETMASK, SIOCSIFNETMASK

Get or set the network mask for a device using ifr_netmask. for compatibility, only AF_INET addresses are accepted or returned. setting the network mask is a privileged operation.

SIOCGIFMETRIC, SIOCSIFMETRIC

Get or set the metric of the device using ifr_metric. bestie this one is currently not implemented โ€” it sets ifr_metric to 0 if you attempt to read it, and returns EOPNOTSUPP if you attempt to set it. ๐Ÿ’€

SIOCGIFMTU, SIOCSIFMTU

Get or set the MTU (Maximum Transfer Unit) of a device using ifr_mtu. setting the MTU is a privileged operation.

โš ๏ธ okay this part is serious: setting the MTU to too small values may cause kernel crashes. do not play with that. fr fr. ๐Ÿšจ

SIOCGIFHWADDR, SIOCSIFHWADDR

Get or set the hardware address of a device using ifr_hwaddr. the hardware address is specified in a struct sockaddr. sa_family contains the ARPHRD_* device type, sa_data the L2 hardware address starting from byte 0. setting the hardware address is a privileged operation.

SIOCSIFHWBROADCAST

Set the hardware broadcast address of a device from ifr_hwaddr. this is a privileged operation.

SIOCGIFMAP, SIOCSIFMAP

Get or set the interface's hardware parameters using ifr_map. setting the parameters is a privileged operation.

struct ifmap {
    unsigned long   mem_start;
    unsigned long   mem_end;
    unsigned short  base_addr;
    unsigned char   irq;
    unsigned char   dma;
    unsigned char   port;
};

The interpretation of the ifmap structure depends on the device driver and the architecture. so like, it's giving chaos but that's just how it is. ๐ŸŒ€

SIOCADDMULTI, SIOCDELMULTI

Add an address to or delete an address from the device's link layer multicast filters using ifr_hwaddr. these are privileged operations. See also packet(7) for an alternative. ๐ŸŽ€

SIOCGIFTXQLEN, SIOCSIFTXQLEN

Get or set the transmit queue length of a device using ifr_qlen. setting the transmit queue length is a privileged operation.

SIOCSIFNAME

Changes the name of the interface specified in ifr_name to ifr_newname. this is a privileged operation. and it is allowed only when the interface is not up. no renaming while she's running, periodt. ๐Ÿ’…

SIOCGIFCONF

Return a list of interface (network layer) addresses. this currently means only addresses of the AF_INET (IPv4) family, for compatibility. unlike the others, this ioctl passes an ifconf structure:

struct ifconf {
    int               ifc_len; /* size of buffer */
    union {
        char         *ifc_buf; /* buffer address */
        struct ifreq *ifc_req; /* array of structures */
    };
};

If ifc_req is NULL, SIOCGIFCONF returns the necessary buffer size in bytes for receiving all available addresses in ifc_len. Otherwise, ifc_req contains a pointer to an array of ifreq structures to be filled with all currently active L3 interface addresses. ifc_len contains the size of the array in bytes. within each ifreq structure, ifr_name will receive the interface name, and ifr_addr the address. the actual number of bytes transferred is returned in ifc_len. โœจ

If the size specified by ifc_len is insufficient to store all the addresses, the kernel will skip the exceeding ones and return success. there is no reliable way of detecting this condition once it has occurred. ๐Ÿ˜ญ it is therefore recommended to either determine the necessary buffer size beforehand by calling SIOCGIFCONF with ifc_req set to NULL, or to retry the call with a bigger buffer whenever ifc_len upon return differs by less than sizeof(struct ifreq) from its original value. do it the safe way bestie, trust. ๐Ÿซถ

If an error occurs accessing the ifconf or ifreq structures, EFAULT will be returned.

Most protocols support their own ioctls to configure protocol-specific interface options. see the protocol man pages for a description. for configuring IP addresses, see ip(7).

In addition, some devices support private ioctls. these are not described here. mysterious. love that for them. ๐Ÿ™ˆ


๐ŸŒˆ NOTES ๐ŸŒˆ

SIOCGIFCONF and the other ioctls that accept or return only AF_INET socket addresses are IP-specific and perhaps should rather be documented in ip(7). that's the tea. โ˜•

The names of interfaces with no addresses or that don't have the IFF_RUNNING flag set can be found via /proc/net/dev. ๐Ÿ“

AF_INET6 IPv6 addresses can be read from /proc/net/if_inet6 or via rtnetlink(7). adding a new IPv6 address and deleting an existing IPv6 address can be done via SIOCSIFADDR and SIOCDIFADDR or via rtnetlink(7). retrieving or changing destination IPv6 addresses of a point-to-point interface is possible only via rtnetlink(7). only. no other way. ๐Ÿ’œ


๐Ÿ’€ BUGS ๐Ÿ’€

glibc 2.1 is missing the ifr_newname macro in <net/if.h>. bestie that's rough. ๐Ÿ˜ญ add the following to your program as a workaround:

#ifndef ifr_newname
#define ifr_newname     ifr_ifru.ifru_slave
#endif

๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

proc(5), capabilities(7), ip(7), rtnetlink(7)


and that's the whole page, no crumbs left ๐Ÿ’– this was Linux man-pages 6.20, dated 2026-02-08 โ€” go configure some network devices, you absolute icon ๐Ÿ‘‘โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-1-para
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms