Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Question about binding a port to an IP adress

hermsen
2022-01-05
2022-01-05
  • hermsen

    hermsen - 2022-01-05

    Hi All,

    My question is fairly simple;

    If I select 127.0.0.1 in RPi and bind port 502 to it,
    will it automagically be available for ALL configured IP adresses on the RPi?

    Eg: I bind to 127.0.0.1, in my example, port 502 will be exposed on 192.168.168.14 (eth0) AND 192.168.168.15 (wlan0)?

    -> If I bind to 192.168.168.14 , in my example port 502 will be exposed on 192.168.168.14 (eth0) ONLY.

    -> If I bind to 192.168.168.15 , in my example it will be exposed on 192.168.168.15 (wlan0) ONLY.

    Is this assumption correct?

    Many thanks.

     

    Last edit: hermsen 2022-01-05
  • nothinrandom - 2022-01-05

    πŸ‘‹ @h-hermsen,

    127.0.0.1 is a virtual interface that is typically referenced as localhost and serves as loopback traffic. It's mainly used to diagnostic within the host itself since traffic can't go anywhere outside... listening (binding) to localhost would work across services if their traffic also originated from the same host.

    • If you want your service to listen on all interfaces, then you could listen on 0.0.0.0 instead.

    In Linux, a good way of checking to see what services are listening to what ports is to use the following command lsof -i -P -n. In Windows, netstat -a.

     
    πŸ‘
    1
  • hermsen

    hermsen - 2022-01-05

    @i-campbell, @nothinrandom
    Thank you all for the clear anwsers :-)

     

    Last edit: hermsen 2022-01-05

Log in to post a comment.