Skip to content
uencoder

SO_BINDTODEVICE

SO_BINDTODEVICE binds a socket to a specific network interface (e.g., eth0) so traffic is sent and received only through that interface.

Purpose

It selects the egress interface in multi-NIC environments, used for VPNs, routing, and interface isolation.

Mechanism

setsockopt(SOL_SOCKET, SO_BINDTODEVICE, ifname) binds the socket to the named interface, restricting all sends and receives to it. It requires root privileges and is used for policy routing and interface-pinned services.

Use cases

  • Multi-NIC routing control
  • VPN interface binding
  • Network isolation

Related tools

References