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.41k stars 347 forks source link

How to set up this service on ECS servers and cloud servers? I want to detect the current NAT type on the client side The server only has one public IP and one internal IP #59

Open apsara2825 opened 4 months ago

jselbie commented 4 months ago

Groan... I used to know how to do this quite well. But now it appears that Amazon has changed how to setup multi-network instances.

Ok, I see how to do this now. It's not obvious.

In the "Network Settings" panel for the instance configuration before you launch it... click "Edit"

image

Change the subnet option from "No preference" to an explicit selection.

image

That should activate the visibility of the "Advanced network configuration" drop down:

image

At the bottom of that expansion, there's a button for "Add network interface"

image

I forgot how I did this last year. But it appears that I use one elastic IP address and assigned that to the secondary adapter.

As for the Stunserver code itself. Explicitly use the --primaryadvertised and --altadvertised command line parameter and specify the public ip addresses as each.

Then use the --primaryinterface and --altinterface command line parameters to specify which local (private) ip address the code should listen for.

Example:

./stunserver --ddp --mode full --family 4 --protocol udp --primaryinterface 172.31.10.101 --altinterface 172.31.10.102 --primaryadvertised 3.135.212.85 --altadvertised 3.132.228.249
jselbie commented 4 months ago

Does this help?

apsara2825 commented 4 months ago

这有帮助吗?

Thank you very much for your reply. I have followed your method carefully, but my ECS server can only be assigned one public IPV4, but there can be multiple private 192.168.0.0/16 addresses. Do you need two public addresses to achieve NAT type detection

apsara2825 commented 4 months ago

Does this help? My server is not an elastic ECS. I tried to purchase an elastic public network, but it prompted me that I cannot bind to my ECS instance. This is too regrettable