STUN module
Admin Guide
Section titled “Admin Guide”Overview
Section titled “Overview”The idea
Section titled “The idea”A stun server working with the same port as SIP (5060) in order to gain accurate information. The benefit would be an exact external address in the case of NATs translating differently when given different destination ports. The server may also advertise different network addresses than the ones it is actually listening on.
Basic Operation
Section titled “Basic Operation”The stun server will use 4 sockets:
- socket1 = ip1 : port1
- socket2 = ip1 : port2
- socket3 = ip2 : port1
- socket4 = ip2 : port2
where ip1 / port1 represent an UDP SIP listener and ip2 / port2 are configured via the alternate ip and alternate port parameters.
The sockets come from existing SIP sockets or are created.
Socket1 must allways be a SIP UDP listener from OpenSIPS.
If use listeners as primary is enabled the STUN server will actually use multiple sets of sockets obtained from the IP/port combinations described above, each set corresponding to a SIP UDP listener from OpenSIPS.
The server will create a separate process. This process will listen for data on created sockets. The server will register a callback function to SIP. This function is called when a specific (stun)header is found.
Supported STUN Attributes
Section titled “Supported STUN Attributes”This stun implements RFC3489 (and XOR_MAPPED_ADDRESS from RFC5389)
- MAPPED_ADDRESS
- RESPONSE_ADDRESS
- CHANGE_REQUEST
- SOURCE_ADDRESS
- CHANGED_ADDRESS
- ERROR_CODE
- UNKNOWN_ATTRIBUTES
- REFLECTED_FROM
- XOR_MAPPED_ADDRESS
Not supported attributes:
- USERNAME
- PASSWORD
- MESSAGE_INTEGRITY
and associated ERROR_CODEs
Dependencies
Section titled “Dependencies”OpenSIPS Modules
Section titled “OpenSIPS Modules”The following modules must be loaded before this module:
None.
External Libraries or Applications
Section titled “External Libraries or Applications”The following libraries or applications must be installed before running OpenSIPS with this module loaded:
- None.
Exported Parameters
Section titled “Exported Parameters”primary_ip (str)
Section titled “primary_ip (str)”The IP of an interface which is configured as an UDP SIP listener in OpenSIPS. This is a mandatory parameter, unless use listeners as primary is enabled.
Syntax: “ip [/ advertised_ip]
By default, the primary_ip and the advertised primary_ip will be identical. This may be changed with an optional ”/ xxx.xxx.xxx.xxx” string.
...modparam("stun", "primary_ip", "192.168.0.100")
# Example of a STUN server within OpenSIPS which is behind NATmodparam("stun", "primary_ip", "192.168.0.100 / 64.50.46.78")...primary_port (str)
Section titled “primary_port (str)”The port configured (together with the primary_ip) as an UDP SIP listener in OpenSIPS. The default value is 5060.
Syntax: “port [/ advertised_port]
By default, the primary_port and the advertised primary_port will be identical. This may be changed with an optional ”/ adv_port” string.
...modparam("stun", "primary_port", "5060")
# Listening on a primary port, but advertising a different onemodparam("stun", "primary_port", "5060 / 5062")...alternate_ip (str)
Section titled “alternate_ip (str)”Another IP from another interface. This is a mandatory parameter.
If use listeners as primary is enabled, the alternate IP must be either:
- an IP from an existing UDP SIP listener configured in OpenSIPS, but one that is different from all the other UPD listeners;
- an IP that is different from the UDP SIP listeners configured in OpenSIPS.
Syntax: “ip [/ advertised_ip]
By default, the alternate_ip and the advertised alternate_ip will be identical. This may be changed with an optional ”/ xxx.xxx.xxx.xxx” string.
...modparam("stun","alternate_ip","11.22.33.44")
# Example of a STUN server within OpenSIPS which is behind NATmodparam("stun", "alternate_ip", "192.168.0.100 / 64.78.46.50")...alternate_port (str)
Section titled “alternate_port (str)”The port used by the STUN server for the second interface. The default value is 3478 (default STUN port).
If use listeners as primary is enabled, the alternate port must be either:
- a port from an existing UDP SIP listener configured in OpenSIPS, but one that is different from all the other UPD listeners;
- a port that is different from the UDP SIP listeners configured in OpenSIPS.
Syntax: “port [/ advertised_port]
By default, the alternate_port and the advertised alternate_port will be identical. This may be changed with an optional ”/ adv_port” string.
...modparam("stun","alternate_port","3479")
# Listening on an alternate port, but advertising a different onemodparam("stun", "alternate_port", "5060 / 5062")...use_listeners_as_primary (int)
Section titled “use_listeners_as_primary (int)”Setting this parameter to 1 will allow all configured UDP SIP listeners to be automatically used as “primary” STUN sockets.
The primary ip and primary port parameters will be ignored when this behavior is enabled.
The default value is 0 (disabled).
...modparam("stun","use_listeners_as_primary",1)...Contributors
Section titled “Contributors”By Commit Statistics
Section titled “By Commit Statistics”Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
| # | Name | DevScore | Commits | Lines++ | Lines— |
|---|---|---|---|---|---|
| 1. | Bogdan-Andrei Iancu (@bogdan-iancu) | 25 | 14 | 412 | 397 |
| 2. | Razvan Pistolea | 20 | 3 | 1891 | 19 |
| 3. | Liviu Chircu (@liviuchircu) | 19 | 13 | 283 | 134 |
| 4. | Razvan Crainea (@razvancrainea) | 15 | 13 | 29 | 22 |
| 5. | Vlad Paiu (@vladpaiu) | 7 | 5 | 30 | 9 |
| 6. | Stefan Darius (@dariusstefan) | 7 | 3 | 303 | 42 |
| 7. | Bernard | 7 | 1 | 430 | 114 |
| 8. | Maksym Sobolyev (@sobomax) | 4 | 2 | 2 | 3 |
| 9. | Peter Lemenkov (@lemenkov) | 3 | 1 | 1 | 1 |
| 10. | Vlad Patrascu (@rvlad-patrascu) | 2 | 1 | 1 | 0 |
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits
(3) ignoring whitespace edits, renamed files and auto-generated files
By Commit Activity
Section titled “By Commit Activity”| # | Name | Commit Activity |
|---|---|---|
| 1. | Stefan Darius (@dariusstefan) | Jun 2026 - Jul 2026 |
| 2. | Razvan Crainea (@razvancrainea) | Oct 2011 - Jun 2026 |
| 3. | Liviu Chircu (@liviuchircu) | Mar 2014 - Sep 2025 |
| 4. | Bogdan-Andrei Iancu (@bogdan-iancu) | Sep 2009 - May 2023 |
| 5. | Maksym Sobolyev (@sobomax) | Feb 2023 - Feb 2023 |
| 6. | Bernard | Oct 2021 - Oct 2021 |
| 7. | Vlad Paiu (@vladpaiu) | Sep 2011 - Aug 2019 |
| 8. | Peter Lemenkov (@lemenkov) | Jun 2018 - Jun 2018 |
| 9. | Vlad Patrascu (@rvlad-patrascu) | May 2017 - May 2017 |
| 10. | Razvan Pistolea | Sep 2009 - Sep 2009 |
(1) including any documentation-related commits, excluding merge commits
Documentation
Section titled “Documentation”Contributors
Section titled “Contributors”Last edited by: Razvan Crainea (@razvancrainea), Bernard, Peter Lemenkov (@lemenkov), Liviu Chircu (@liviuchircu), Bogdan-Andrei Iancu (@bogdan-iancu), Razvan Pistolea.
License
Section titled “License”All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0