jselbie / stunserver

Version 1.2. This is the source code to STUNTMAN - an open source STUN server and client code by john selbie. Compliant with the latest RFCs including 5389, 5769, and 5780. Also includes backwards compatibility for RFC 3489. Compiles on Linux, MacOS, BSD, Solaris, and Win32 with Cygwin. Windows binaries avaialble from www.stunprotocol.org.
http://www.stunprotocol.org
Apache License 2.0
1.44k stars 349 forks source link

If I use the external IP the binding test fails : What am I doing wrongly? How to correctly obtain Mapped Address from Stunman Server? #41

Open raphael10-collab opened 3 years ago

raphael10-collab commented 3 years ago

I compiled in Ubuntu 20.04 stunserver. Now I'm trying to understand how to make it properly work.

If I use the IP of the local network, then the binding test succeed.

(base) raphy@pc:~/stunserver$ ./stunclient --mode behavior 192.168.1.7 --verbosity 9
Resolved 192.168.1.7 to 192.168.1.7:0
config.fBehaviorTest = true
config.fFilteringTest = false
config.timeoutSeconds = 0
config.uMaxAttempts = 0
config.addrServer = 192.168.1.7:3478
socketconfig.addrLocal = 0.0.0.0:0
Sending message to 192.168.1.7:3478
Got response (56 bytes) from 192.168.1.7:3478 on interface 192.168.1.7:38521
Binding test: success
Local address: 192.168.1.7:38521
Mapped address: 192.168.1.7:38521
Behavior test: success
Nat behavior: Direct Mapping

If I use the external IP , then the binding test fails :

(base) raphy@pc:~/stunserver$ ./stunclient --mode behavior 109.116.136.120 --verbosity 9
Resolved 109.116.136.120 to 109.116.136.120:0
config.fBehaviorTest = true
config.fFilteringTest = false
config.timeoutSeconds = 0
config.uMaxAttempts = 0
config.addrServer = 109.116.136.120:3478
socketconfig.addrLocal = 0.0.0.0:0
Sending message to 109.116.136.120:3478
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Sending message to 109.116.136.120:3478
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Binding test: fail
Behavior test: fail

What am I doing wrongly? How to correctly obtain Mapped Address from Stunman Server?

jselbie commented 3 years ago

If I read this correctly, your server is behind a NAT, which is fine. But you are using your client to connect to your local server via the external IP address. This means that your NAT needs to support a mode called hairpinning https://en.wikipedia.org/wiki/Hairpinning. Not all NATs support this mode that enables clients behind the NAT to hit another node behind the same NAT via the external IP.

You could try port forwarding from port 3478 to your 192.168.1.7 address. That might enable hairpinning to work.

It's rather unusual for an actual P2P or RTC session to rely on a stunserver running on the same device as the client. Most servers run on the public internet.

On Thu, Jul 22, 2021 at 5:26 AM raphael10-collab @.***> wrote:

I compiled in Ubuntu 20.04 stunserver. Now I'm trying to understand how to make it properly work.

If I use the IP of the local network, then the binding test succeed.

(base) @.***:~/stunserver$ ./stunclient --mode behavior 192.168.1.7 --verbosity 9 Resolved 192.168.1.7 to 192.168.1.7:0 config.fBehaviorTest = true config.fFilteringTest = false config.timeoutSeconds = 0 config.uMaxAttempts = 0 config.addrServer = 192.168.1.7:3478 socketconfig.addrLocal = 0.0.0.0:0 Sending message to 192.168.1.7:3478 Got response (56 bytes) from 192.168.1.7:3478 on interface 192.168.1.7:38521 Binding test: success Local address: 192.168.1.7:38521 Mapped address: 192.168.1.7:38521 Behavior test: success Nat behavior: Direct Mapping

If I use the external IP , then the binding test fails :

(base) @.***:~/stunserver$ ./stunclient --mode behavior 109.116.136.120 --verbosity 9 Resolved 109.116.136.120 to 109.116.136.120:0 config.fBehaviorTest = true config.fFilteringTest = false config.timeoutSeconds = 0 config.uMaxAttempts = 0 config.addrServer = 109.116.136.120:3478 socketconfig.addrLocal = 0.0.0.0:0 Sending message to 109.116.136.120:3478 Continuing to wait for response... Continuing to wait for response... Continuing to wait for response... Continuing to wait for response... Continuing to wait for response... Sending message to 109.116.136.120:3478 Continuing to wait for response... Continuing to wait for response... Continuing to wait for response... Continuing to wait for response... Continuing to wait for response... Binding test: fail Behavior test: fail

What am I doing wrongly? How to correctly obtain Mapped Address from Stunman Server?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jselbie/stunserver/issues/41, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHNSF4NFO2R3USHZASWD6TTZAFAZANCNFSM5AZ42GCQ .

raphael10-collab commented 3 years ago

Hi @jselbie ! Thank you for your kind prompt reply and interesting explanation.

Actually, what I'm trying to do, is to "simulate" and "emulate" in a local environment, what I will then deploy in a larger mixed, local + cloud, environment. I've created within my local Ubuntu 20.04 a Linux Container, that I called "ubuntuone" with Ubuntu 20.04 as well. Within this Linux Container I installed stunserver :

(base) raphy@pc:~$ lxc exec ubuntuone -- /bin/bash
root@ubuntuone:~# cd stunserver/
root@ubuntuone:~/stunserver# ./stunserver 

root@ubuntuone:~/stunserver# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.65.116.195  netmask 255.255.255.0  broadcast 10.65.116.255
        inet6 fe80::216:3eff:fe5b:de10  prefixlen 64  scopeid 0x20<link>
        inet6 fd42:2159:3d69:bcae:216:3eff:fe5b:de10  prefixlen 64  scopeid 0x0<global>
        ether 00:16:3e:5b:de:10  txqueuelen 1000  (Ethernet)
        RX packets 18298  bytes 9488015 (9.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20985  bytes 10002524 (10.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 27  bytes 2537 (2.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 27  bytes 2537 (2.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@ubuntuone:~/stunserver# 

If I "call" from the outer system the contained stunserver I do not get any errors :

(base) raphy@pc:~/stunserver$ ./stunclient --mode behavior 10.65.116.195 --verbosity 9
Resolved 10.65.116.195 to 10.65.116.195:0
config.fBehaviorTest = true
config.fFilteringTest = false
config.timeoutSeconds = 0
config.uMaxAttempts = 0
config.addrServer = 10.65.116.195:3478
socketconfig.addrLocal = 0.0.0.0:0
Sending message to 10.65.116.195:3478
Got response (56 bytes) from 10.65.116.195:3478 on interface 10.65.116.1:33876
Binding test: success
Local address: 10.65.116.1:33876
Mapped address: 10.65.116.1:33876
Behavior test: success
Nat behavior: Direct Mapping

Does this sound correct to you, or am I making things more complicated than they could be, keeping in mind that my objective is to emulate and simulate locally what I will deploy in a broader environment?

jselbie commented 3 years ago

This is one of those things where I would really need to see a complete picture or diagram of your network topology before I could give a correct answer. It might be a simple command line switch or network configuration change. But it's rather unusual what you are doing.

What are you really trying to do?

raphael10-collab commented 3 years ago

I sketched a representation of the network I have in mind.

Doing it, I actually realized that trying to simulate locally what it is not by its nature, is not that clever and even possible.

NetworkRepresentation

So, even if I'm departing from my original issue's subject, I ask you: based on your experience, how would you test, may be using cloud services providers (AWS, Azure,...) this kind of network topology? Thank you in advance for your kind help