do i have to keep port 4001 open to make my files reachable?

Suddenly, if I upload a file to IPFS and then try to reach it by entering the URL it loads endlessly. Thanks to some tips here on your forum I solved it by opening the door 4001. Is it dangerous to keep this door open? By doing this I solved the problem but how come it worked before even with this door closed?

TLDR: yes, and you got lucky.

Your node is the server for anything you put up on IPFS. If your node isn’t reachable (port 4001 is blocked, or the node isn’t running), no one can download your files. If you’d like to be able to shut your node down at times, then you need to pin your files on another server as well (there are services that do that, such as Piñata). Now, the rest of the network acts as a CDN for your content, so if your content is popular, other nodes will have it in their cache (for a time) and it can be downloaded from there as well. However, you can’t rely on it staying there, as caches rotate over time. So, your content must be pinned in at least one place (your node, or a pinning service) for your content to remain reachable.

It worked before because your node happened to have dialed the gateway you used to try and retrieve your content. The odds of that happening are pretty low, you just got lucky. It is also transient, your node doesn’t stay connected to the same nodes over time, so you can’t rely on that either (and shouldn’t).

Now, is it dangerous to run a service on the internet (yes, your node is running a publicly accessible service)? Well, if there is a security bug in the node code, and someone knows how to use it to gain access to the computer, and they want to access yours, then, yes. On the flip side, every IPFS node on the internet is doing it to function.

1 Like