If I send data to my computer using its public hostname, does it actually go over the internet?

To clarify:

I'm using my public hostname to connect to a MySQL database. The hostname resolves to my server's external IP (e.g. 1.2.3.4). Is the data I'm sending/receiving via the MySQL connection going over the internet at all? Would it be faster to use localhost? Will it take up my server's bandwidth?


Solution 1:

If you want to be sure, you can use traceroute 1.2.3.4. This will list all the routers between the host running the command and the device with 1.2.3.4 IP address.

Solution 2:

If you use "localhost" as hostname for connecting to your MySQL server, MySQL won't use TCP, but sockets. This should be the fastest way to connect to a locally running MySQL server.

If your server has the external IP set up "properly", that is, it is not behind a firewall or proxy in an internal network, the traffic won't leave your server as it knows that the target IP address is the same system.

Solution 3:

You don't mention anything about your routing or switching equipment but you could go out of your way to ensure your data goes outside before coming back but in reality almost certainly your data won't be going out this way.

Solution 4:

No if all is on one machine it does not leave the machine.

Solution 5:

if your server ip configuration on its machine uses the public IP address, then no traffic will leave your server (but its safer to be sure and use localhost anyway for the performance benefits)

if your IP is nat'ed and your router has the public ip and your server has an internal IP then at the very least traffic will likely leave your server and be reflected back onto your server from the router assuming that the router does port reflection as part of its port forwarding - so in a sense no traffic will leave your network but some traffic will leave your server

without any network setup info i cant be more definitive than that