<!--
{
  "availability" : [
    "macOS: 10.15.0 - 15.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "NetworkExtension",
  "identifier" : "/documentation/NetworkExtension/NENetworkRule/init(remoteNetwork:remotePrefix:localNetwork:localPrefix:protocol:direction:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NENetworkRule(im)initWithRemoteNetwork:remotePrefix:localNetwork:localPrefix:protocol:direction:"
  },
  "title" : "init(remoteNetwork:remotePrefix:localNetwork:localPrefix:protocol:direction:)"
}
-->

# init(remoteNetwork:remotePrefix:localNetwork:localPrefix:protocol:direction:)

Creates a rule that matches traffic by remote network, local network, protocol, and direction.

```
init(remoteNetwork: NWHostEndpoint?, remotePrefix: Int, localNetwork: NWHostEndpoint?, localPrefix: Int, protocol: NENetworkRule.Protocol, direction: NETrafficDirection)
```

## Parameters

`remoteNetwork`

An endpoint instance that contains the remote port and the remote address or network that the rule matches. This endpoint must contain an address, not a hostname.

`remotePrefix`

An integer that in combination with the address in `remoteNetwork` specifies the remote network that the rule matches.

`localNetwork`

An endpoint instance that contains the local port and the local address or network that the rule matches. This endpoint must contain an address, not a hostname.

`localPrefix`

An integer that in combination with the address in localNetwork specifies the local network that the rule matches. The rule ignores this parameter if `localNetwork` is `nil`.

`protocol`

The protocol that the rule matches.

`direction`

The direction of network traffic that the rule matches.

## Discussion

If the port string of `remoteNetwork` is `0` or the empty string, then the rule matches traffic on any port coming from the remote network. If `remoteNetwork` is `nil`, the rule matches any remote network.

If the port string of `localNetwork` is `0` or the empty string, then the rule matches traffic on any port coming from the local network. If `localNetwork` is `nil`, the rule matches any local network.

---

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)