3

we assume that the server has the IP addresses "111.111.111.111" and "222.222.222.222" (host ip) and I want to bind IRI to the ip 111.111.111.111

PORT = 14265
UDP_RECEIVER_PORT = 14600
TCP_RECEIVER_PORT = 15600
API_HOST = 111.111.111.111

but netstat -tulpen shows

Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name
tcp        0      0 0.0.0.0:15600           0.0.0.0:*               LISTEN      1000       20735      662/java
tcp        0      0 111.111.111.111:14265   0.0.0.0:*               LISTEN      1000       20757      662/java
udp        0      0 0.0.0.0:14600           0.0.0.0:*                           1000       20729      662/java

which leads to the problem that my neighbors are trying to communicate with 222.222.222.222 which is the host (not IRI) ip.

 ***** NETWORK ALERT ***** TCP connection reset by neighbor 222.222.222.222, source closed, Connection reset
1
  • in order to reproduce the problem, the IRI ip must not be at the end in the /etc/hosts otherwise it is only used because of the order in the hosts. Commented Dec 1, 2017 at 13:02

1 Answer 1

2

IRI works in simplex mode, meaning that one TCP connection is used for receiving and another for sending.

Your IRI TCP and UDP receivers are automatically bound to both IP addresses via "catch-all" 0.0.0.0 address. This means that your neighbours can select which IP they prefer (provided that both are open to the public, of course). TCP and UDP receiver addresses therefore have no influence on the IP address that is visible to your peers when they are sending packets to you.

As for your outgoing traffic - IP address which is visible to your neighbours when you are connecting/sending packets to them) - a quick glance at the IRI source code reveals that IRI does not implement socket source address binding before connecting, therefore the source address selection is left to your operating system. This is quite normal.

I assume you're running IRI on Linux;

  • If you want to change the default outgoing IP address for all outgoing connections, you can use ip route command (e.g. ip route change default via <default gw> src <your new source addr.>), or
  • you can use iptables SNAT target for more specific address selection based on various source/destination address, port, etc. criteria (e.g. iptables -t nat -A POSTROUTING --destination <destionation address> -j SNAT --to-source <your new source address>).
2
  • of course you can do this with routing but I think it's the application's thing. Commented Dec 2, 2017 at 13:35
  • 1
    Lucky node operators who have servers with two network interfaces with two public IPs. :-) Anyway, it shouldn't be a huge thing adding this to IRI. After opening new outgoing socket and before connecting (or sending datagram packet n case of UDP), another call is needed - bind socket to a configurable IP address. Should take a seasoned IRI developer some 2 minutes to implement. Commented Dec 2, 2017 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.