At my home I have my desktop computer behind a router. There's a port forwarded by the router to the computer's ssh port. When I am using my laptop in the same LAN, I can either connect to my desktop computer on 192.168.1.something or just connect to the router's address on the internet. Does it matter which way I do it in terms of routing, speed and ping?
3 Answers
If you're using the public IPv4 address (visible to the Internet), then the network traffic gets sent to the device with that address. That would be your router. This means your router needs to receive the traffic. Then, your router is noticing that there is a forwarded port, so it converts the network traffic's IP address and then sends the converted network traffic to the laptop. This is a heavier burden than required, overworking the router.
If you have a switch between your devices and the router, the switch may be getting used multiple times as well. Even if that's not the case and the router's multiple LAN ports are being used like a switch, using the internal addresses will allow the router to basically act like a switch when handling the traffic, which likely requires a lower burden on the router, meaning that the router can process the traffic more quickly.
Another benefit: If you use internal addresses, and then if your router dies, you can replace the router with a switch and your internal communication is much more likely to work with minimal (quite possibly no) change.
So long as it works it doesn't matter. However you will probably get better performance by using the LAN address and thus, not involving the router.
connect directly to 192.168.1.something will faster. your packages data does not need to passthrough router forwarder. communication will be established in OSI layer 2.