Dynamic LocalAddress for net.Dialer

Hey all

I have several net interfaces with different IP networks on my machine. I am trying to define dynamic LocalAddress for net.Dialer{} (random IP per request to avoid running out of ports), but so far without success.
The only idea for now it is to create pool of handlers, each one with own transport on different IP and draw randomly from them, but maybe there is easier way?

I am thinking about something like:

defaultTransport: &http.Transport{				
	Dial: (&net.Dialer{
		LocalAddr: getDynamicLocalAddress(),

Which obviously will draw only once during setting up listener.

What is the scenario that would make you run out of ports? (I’ve never heard of this being an actual problem.) If the remote side varies you can use a single port for all your outgoing connections.

It is kind of reverse proxy, so you have limit of opened connections to upstreams (different ones). Anyway the question is how to specify the Transport which will randomly draw the outgoing IP / Interface

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.