Section: Linux Programmer's Manual (7)

Updated: 2014-01-24

Index?action=index Return to Main Contents


netdevice - low-level access to Linux network devices


#include <sys/ioctl.h>

#include <net/if.h>


This man page describes the sockets interface which is used to configure network devices.

Linux supports some standard ioctls to configure network devices. They can be used on any socket's file descriptor regardless of the family or type. Most of them pass an ifreq structure:

Normally, the user specifies which device to affect by setting ifr_name to the name of the interface. All other members of the structure may share memory.


If an ioctl is marked as privileged, then using it requires an effective user ID of 0 or the CAP_NET_ADMIN capability. If this is not the case, EPERM will be returned.

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.:
Retrieve the interface index of the interface into ifr_ifindex.:
Get or set the active flag word of the device. ifr_flags contains a bit mask of the following values:

<TABLE> <TR VALIGN="top| <TD ALIGN="center" COLSPAN="2|Device flags

</TD> </TR> <TR VALIGN="top| <TD>IFF_UP</TD> <TD>Interface is running.

</TD> </TR> <TR VALIGN="top| <TD>IFF_BROADCAST</TD> <TD>Valid broadcast address set.

</TD> </TR> <TR VALIGN="top| <TD>IFF_DEBUG</TD> <TD>Internal debugging flag.

</TD> </TR> <TR VALIGN="top| <TD>IFF_LOOPBACK</TD> <TD>Interface is a loopback interface.

</TD> </TR> <TR VALIGN="top| <TD>IFF_POINTOPOINT</TD> <TD>Interface is a point-to-point link.

</TD> </TR> <TR VALIGN="top| <TD>IFF_RUNNING</TD> <TD>Resources allocated.

</TD> </TR> <TR VALIGN="top| <TD>IFF_NOARP</TD> <TD>No arp protocol, L2 destination address not set.

</TD> </TR> <TR VALIGN="top| <TD>IFF_PROMISC</TD> <TD>Interface is in promiscuous mode.

</TD> </TR> <TR VALIGN="top| <TD>IFF_NOTRAILERS</TD> <TD>Avoid use of trailers.

</TD> </TR> <TR VALIGN="top| <TD>IFF_ALLMULTI</TD> <TD>Receive all multicast packets.

</TD> </TR> <TR VALIGN="top| <TD>IFF_MASTER</TD> <TD>Master of a load balancing bundle.

</TD> </TR> <TR VALIGN="top| <TD>IFF_SLAVE</TD> <TD>Slave of a load balancing bundle.

</TD> </TR> <TR VALIGN="top| <TD>IFF_MULTICAST</TD> <TD>Supports multicast

</TD> </TR> <TR VALIGN="top| <TD>IFF_PORTSEL</TD> <TD>Is able to select media type via ifmap.

</TD> </TR> <TR VALIGN="top| <TD>IFF_AUTOMEDIA</TD> <TD>Auto media selection active.

</TD> </TR> <TR VALIGN="top| <TD>IFF_DYNAMIC</TD> <TD>The addresses are lost when the interface goes down.

</TD> </TR> <TR VALIGN="top| <TD>IFF_LOWER_UP</TD> <TD>Driver signals L1 up (since Linux 2.6.17)

</TD> </TR> <TR VALIGN="top| <TD>IFF_DORMANT</TD> <TD>Driver signals dormant (since Linux 2.6.17)

</TD> </TR> <TR VALIGN="top| <TD>IFF_ECHO</TD> <TD>Echo sent packets (since Linux 2.6.25)

</TD> </TR> <TR VALIGN="top| <TD></TD> <TD>

</TD> </TR> </TABLE> Setting the active flag word is a privileged operation, but any process may read it.:

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

<TABLE> <TR VALIGN="top| <TD ALIGN="center" COLSPAN="2|Private flags

</TD> </TR> <TR VALIGN="top| <TD>IFF_802_1Q_VLAN</TD> <TD>Interface is 802.1Q VLAN device.

</TD> </TR> <TR VALIGN="top| <TD>IFF_EBRIDGE</TD> <TD>Interface is Ethernet bridging device.

</TD> </TR> <TR VALIGN="top| <TD>IFF_SLAVE_INACTIVE</TD> <TD>Interface is inactive bonding slave.

</TD> </TR> <TR VALIGN="top| <TD>IFF_MASTER_8023AD</TD> <TD>Interface is 802.3ad bonding master.

</TD> </TR> <TR VALIGN="top| <TD>IFF_MASTER_ALB</TD> <TD>Interface is balanced-alb bonding master.

</TD> </TR> <TR VALIGN="top| <TD>IFF_BONDING</TD> <TD>Interface is a bonding master or slave.

</TD> </TR> <TR VALIGN="top| <TD>IFF_SLAVE_NEEDARP</TD> <TD>Interface needs ARPs for validation.

</TD> </TR> <TR VALIGN="top| <TD>IFF_ISATAP</TD> <TD>Interface is RFC4214 ISATAP interface.

</TD> </TR> </TABLE>

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


Get or set the address of the device using ifr_addr. Setting the interface address is a privileged operation. For compatibility, only AF_INET addresses are accepted or returned.:
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.:
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.:
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.:
Get or set the metric of the device using ifr_metric. This 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.:
Get or set the MTU (Maximum Transfer Unit) of a device using ifr_mtu. Setting the MTU is a privileged operation. Setting the MTU to too small values may cause kernel crashes.:
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.:
Set the hardware broadcast address of a device from ifr_hwaddr. This is a privileged operation.:
Get or set the interface's hardware parameters using ifr_map. Setting the parameters is a privileged operation.

The interpretation of the ifmap structure depends on the device driver and the architecture.


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.:
Get or set the transmit queue length of a device using ifr_qlen. Setting the transmit queue length is a privileged operation.:
Changes the name of the interface specified in ifr_name to ifr_newname. This is a privileged operation. It is allowed only when the interface is not up.:
Return a list of interface (transport layer) addresses. This currently means only addresses of the AF_INET (IPv4) family for compatibility. Unlike the others, this ioctl passes an ifconf structure:

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.

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.


Strictly speaking, SIOCGIFCONF and the other ioctls that accept or return only AF_INET socket addresses, are IP-specific and belong in ip?(7).

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

Local IPv6 IP addresses can be found via /proc/net or via rtnetlink?(7).


glibc 2.1 is missing the ifr_newname macro in <net/if.h>. Add the following to your program as a workaround:


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


This page is part of release 3.74 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at