0

My question regards ssh, sftp, scp, rsync, etc. commands where you connect to another machine which can be in your Local Area Network (LAN) or at some remote location you would typically connect via the Wide Area Network (WAN) or greater internet.

For instance, if you were to use these each of these two commands,

ssh user@publicIP.com
ssh user@192.168.0.100

whereby you connect namely to a remote machine or a LAN machine respectively, does the actual connection path change if you are in the same LAN? Note publicIP.com represents the IP address or domain name that applies to both the host and the machine executing this command.

As an example, consider the case you are at home and have two machines connected to the internet through the same router. I would expect the second command to send data from machine1-->router-->machine2. Does the first command do the same or does it do machine1-->router-->some remote path-->router-->machine2? And in the second case, will this contribute to the bandwidth your ISP monitors and caps?

1

First your router is not just a router, it is also a ethernet switch, a DHCP server, A wifi hotspot, a modem, …

2nd it should be routed the best way: if on same sub-net 192.168.0.x then it will be routed by the machines, and not go through the router (not the router part of the router, just the ethernet switch).

What happens when you use a domain name e.g. publicIP.com

  • First the name is looked up: this may be done using /etc/hosts, bonjour/avahi, DNS, or other resolver. (This step may involve asking a public DNS server, so some public traffic. But it is cached for several minutes.)
  • Then an attempt it made to connect to the ip address.

e.g. If we do ssh user@publicIP.com and the DNS A record of publicIP.com is 192.168.0.100, then the DNS look up returns 192.168.0.100. Then ssh does the connection ssh user@192.168.0.100, and therefore routed the same as if you specified 192.168.0.100.

A note on http

In http the original name is also passed to the server (after the connection is made), this is sometimes use to distinguish which virtual server to connect to (at the same IP address).

  • There are 2 difficult things in computing: naming things, cache invalidation, and out by one errors. – ctrl-alt-delor Jun 6 at 16:53
  • Does this mean regardless of the command you use to connect, the machines will find the best route simply because they are on the same sub-net? I think what would be most helpful is a source with minimal jargon that briefly discusses where the data flows and how it decides that path. – T. Zack Crawford Jun 6 at 17:07
  • @T.ZackCrawford I have updated the answer – ctrl-alt-delor Jun 11 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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