Overview
AddressRewriteRule allows you to rewrite local IP addresses with external public IPs for ICE candidates. This is essential for servers behind 1:1 NAT (like AWS EC2 instances) where the local interface has a private IP, but the server is reachable via a public IP.
This replaces the deprecated
NAT1To1IPs configuration field with a more flexible rule-based system.Type Definition
Fields
List of public IP addresses to advertise. For replace mode with an empty list, matched candidates are dropped. For append mode with an empty list, the original candidate is kept.
Specific local IP address to match. When set, external IPs map only to this address. When empty, acts as a catch-all for the IP family.
Network interface name to limit the rule to (e.g., “eth0”). Empty matches all interfaces.
CIDR block to limit the rule to (e.g., “192.168.1.0/24”). Empty matches all addresses.
The candidate type to publish. Supported values:
CandidateTypeHost(default)CandidateTypeServerReflexiveCandidateTypeRelay
Controls whether to replace or append candidates. Default:
AddressRewriteReplacefor host candidatesAddressRewriteAppendfor srflx and relay candidates
Limit the rule to specific network types. Empty or nil matches all networks.
AddressRewriteMode
- Removes the original candidate
- Replaces it with the external IP(s)
- Empty External list drops the candidate entirely
- Keeps the original candidate
- Adds additional candidates with external IP(s)
- Empty External list keeps only the original
Rule Evaluation Order
Rules are evaluated in order with specificity-based matching:- Explicit Local Match: Rules with matching
Localaddress win immediately - Catch-all Priority (most specific first):
- Interface + CIDR
- Interface only
- CIDR only
- Global catch-all
- Declaration Order: Ties are broken by order of addition
Overlapping rules at the same specificity level generate warnings.
Usage Examples
Advanced Patterns
Layered Specificity
Separate IPv4/IPv6
Validation
Rules are validated during agent creation:- External IPs must be valid IP addresses (not CIDR)
- Local address (if set) must be a valid IP
- CIDR (if set) must be valid
- Local address must be within CIDR (if both set)
- Duplicate external IPs are removed
- Empty external lists are allowed (for deny-list patterns)
Migration from NAT1To1IPs
Conflict Warnings
Overlapping rules generate warnings but don’t fail:Compatibility
- mDNS: Address rewrite rules with host candidates are incompatible with
MulticastDNSModeQueryAndGather - Candidate Types: If a rule targets a candidate type that’s disabled, a warning is logged
- ICE-Lite: Host rewrite rules work with ICE-lite mode
Related
- Agent Options - WithAddressRewriteRules function
- CandidateType - Candidate type enum
- NetworkType - Network type enum