## Why isnt a random port chosen for SEED node sockets?

0

I connected a node A to bitcoin testnet (Port 18333). The node discovery happens and I see couple of connections between my node A and the seed nodes. All of the sending and receiving happens between nodes ONLY via Port 18333 (I checked this in ThreadSocketHandler)

I add another node B (different laptop hence different IP) to the bitcoin testnet. I initiate a addnode <lappyB_IP>:18333 onetry connection from A and it gets accepted. But now the port A uses to send data is chosen randomly by OS and NOT 18333. This can be checked by getpeerinfo

We should note that both are outbound connections from A -- namely the first one is we connected to seednode and send one is we connected to another node B. How come in the former data is getting sent via 18333 (default port) but in the later OS decides to chose a different port?

Can you show the getpeerinfo? The addrlocal port should be random for all outbound connections and 18333 for all inbound connections – Dustin Butler – 2016-01-07T06:04:02.050

The addrlocal is empty. So the rpcnet.cpp logic suppresses it in getpeerinfo – Guhan S – 2016-01-07T06:36:27.820

4

All nodes are listening on port 18333 for inbound connections. Any inbound connection will use this port. So addrlocal will show localIP:18333.

Any outbound connection will use a random port so addrlocal will show localIP:xxxxx

So every connection is either random <----> 18333 OR 18333 <----> random. The node that initiated the connection (out) will always use a random port.

This is how all tcp/ip web services with known ports work. Web servers listen on port 80 or port 443, browsers use a random local port to connect to them.

Edit: Should note that port 18333 is for testnet nodes. Would be 8333 for main net. Also if on linux netstat -ntlp or netstat -ntp will show all tcp connections

Is there a possibility to make it 18333 <---> 18333 ? Like passing an option to system call and telling OS to use specified instead of random source port? – Guhan S – 2016-01-07T06:38:08.023

1@GuhanS You can do this on Linux with sysctl net.ipv4.ip_local_port_range="18333 18333" (Note: This will make it so you can only have one outbound connection at once.) – Nick ODell – 2016-01-07T07:03:34.027

1