<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NetworkExtension",
  "identifier" : "/documentation/NetworkExtension/NEPacketTunnelProvider",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NEPacketTunnelProvider"
  },
  "title" : "NEPacketTunnelProvider"
}
-->

# NEPacketTunnelProvider

The principal class for a packet tunnel provider app extension.

```
class NEPacketTunnelProvider
```

## Overview

The [`NEPacketTunnelProvider`](/documentation/NetworkExtension/NEPacketTunnelProvider) class gives its subclasses access to a virtual network interface via the [`packetFlow`](/documentation/NetworkExtension/NEPacketTunnelProvider/packetFlow) property. Use the [`setTunnelNetworkSettings(_:completionHandler:)`](/documentation/NetworkExtension/NETunnelProvider/setTunnelNetworkSettings(_:completionHandler:)) method in the Packet Tunnel Provider to specify that the following network settings be associated with the virtual interface:

- Virtual IP address
- DNS resolver configuration
- HTTP proxy configuration
- IP destination networks to be routed through the tunnel
- IP destination networks to be routed outside the tunnel
- Interface MTU

By specifying IP destination networks, the Packet Tunnel Provider can dictate what IP destinations will be routed to the virtual interface. IP packets with matching destination addresses will then be diverted to Packet Tunnel Provider and can be read using the [`packetFlow`](/documentation/NetworkExtension/NEPacketTunnelProvider/packetFlow) property. The Packet Tunnel Provider can then encapsulate the IP packets per a custom tunneling protocol and send them to a tunnel server. When the Packet Tunnel Provider decapsulates IP packets received from the tunnel server, it can use the [`packetFlow`](/documentation/NetworkExtension/NEPacketTunnelProvider/packetFlow) property to inject the packets into the networking stack.

> Important:
> The `com.apple.developer.networking.networkextension` entitlement is required in order to use the ``doc://com.apple.networkextension/documentation/NetworkExtension/NEPacketTunnelProvider`` class. Enable this entitlement when creating an App ID in your developer account.

### Creating a Packet Tunnel Provider Extension

Packet Tunnel Providers run as App Extensions for the `com.apple.networkextension.packet-tunnel` extension point.

To create a Packet Tunnel Provider extension, first create a new App Extension target in your project.

For an example of an Xcode build target for this app extension, see the [SimpleTunnel: Customized Networking Using the NetworkExtension Framework](https://developer.apple.com/library/archive/samplecode/SimpleTunnel/Introduction/Intro.html#//apple_ref/doc/uid/TP40016140) sample code project.

Once you have a Packet Tunnel Provider extension target, create a subclass of NEPacketTunnelProvider. Then, set the `NSExtensionPrincipalClass` key in the the extension’s `Info.plist` to the name of your subclass.

If it is not already, set the `NSExtensionPointIdentifier` key in the extension’s `Info.plist` to `com.apple.networkextension.packet-tunnel`.

Here is an example of the NSExtension dictionary in a Packet Tunnel Provider extension’s `Info.plist`:

```xml
<key>NSExtension</key>
<dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.networkextension.packet-tunnel</string>
    <key>NSExtensionPrincipalClass</key>
    <string>MyCustomPacketTunnelProvider</string>
</dict>
```

Finally, add the Packet Tunnel Provider extension target to your app’s Embed App Extensions build phase.

### Subclassing Notes

In order to create a Packet Tunnel Provider extension, you must create a subclass of `NEPacketTunnelProvider` and override the methods listed below.

#### Methods to Override

- [`startTunnel(options:completionHandler:)`](/documentation/NetworkExtension/NEPacketTunnelProvider/startTunnel(options:completionHandler:))
- [`stopTunnel(with:completionHandler:)`](/documentation/NetworkExtension/NEPacketTunnelProvider/stopTunnel(with:completionHandler:))

## Topics

### Managing the tunnel life cycle

[`startTunnel(options:completionHandler:)`](/documentation/NetworkExtension/NEPacketTunnelProvider/startTunnel(options:completionHandler:))

Start the network tunnel.

[`stopTunnel(with:completionHandler:)`](/documentation/NetworkExtension/NEPacketTunnelProvider/stopTunnel(with:completionHandler:))

Stop the network tunnel.

[`cancelTunnelWithError(_:)`](/documentation/NetworkExtension/NEPacketTunnelProvider/cancelTunnelWithError(_:))

Stop the network tunnel from the Packet Tunnel Provider.

### Handling IP packets

[`packetFlow`](/documentation/NetworkExtension/NEPacketTunnelProvider/packetFlow)

A [`NEPacketTunnelFlow`](/documentation/NetworkExtension/NEPacketTunnelFlow) object which is used to receive IP packets routed to the tunnel’s virtual interface and inject IP packets into the networking stack via the tunnel’s virtual interface.

### Creating network connections through the tunnel

[`createTCPConnectionThroughTunnel(to:enableTLS:tlsParameters:delegate:)`](/documentation/NetworkExtension/NEPacketTunnelProvider/createTCPConnectionThroughTunnel(to:enableTLS:tlsParameters:delegate:))

Create a TCP connection through the current tunnel.

[`createUDPSessionThroughTunnel(to:from:)`](/documentation/NetworkExtension/NEPacketTunnelProvider/createUDPSessionThroughTunnel(to:from:))

Creates a UDP session through the current tunnel.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)