Could someone guide me on how to achieve this?
Ok, I'm currently following this tutorial: https://create.arduino.cc/projecthub/tylerpeppy/ethernet-controlled-led-4c2586
However I'll still explain the setup:
I've got a computer and Arduino with an ethernet shield. The computer is currently accsessing a page from Arduino's local IP address. Both the computer and the Arduino are currenly on the same network
The page shows 2 buttons, one "on" and one "off." The Arduino reads the value of the buttons and turns on and off an LED.
Ok, so now I'm wondering how I could attach the Arduino's local IP address page to a domain so the page could be accessed from a computer outside of the Arduino's network.
E.g. so a computer could type in (let's say) arduinocontrol.com and see the IP page of the Arduino allowing them to control the Arduino, no matter where in the world the computer is located.
I know from some prior research this may require "port forwarding" and possibibly some thing to do with "Dynamic DNS." I understand that I may even have to buy a server. I don't know much about networking (sorry!) so please try to explain things using simple terms.
Yup. Your router has to be configured to perform port forwarding.
And, your ISP has to allow inbound connections.
Yup.
Depends on what you mean by "a server". Adding a Raspberry Pi to the mix (which you can colloquially call "a server") makes the process a whole lot easier.
Google Domains makes the process very easy. That's who I use. I suggest starting here.
I suspect an Arduino with an ethernet shield is not going to work. I have a recollection of dynamic DNS requiring secure communications (TLS). But, a Raspberry Pi in between should get you what you want.
IP addresses
Your home router generally allocates IP addresses for all the connected devices on the home network. The addresses are often in the 192.168... range, and are only unique on the local network. Millions of local networks will all be using the same local IP addresses.
The router usually also has a connection to the Internet, and when seen from the Internet it will have single unique address - often referred to as its "public IP address". This address is unique, so someone could sent a request to this address, and it will end up at your router. But from there, your router needs to know which local IP address it needs to send it to - that's where "port forwarding" comes in.
In the router's configuration you need to set up rules about what to do when an inbound request arrives on a given port. For example:
port 80 -> forward to 192.168.1.50. Any requests on port 80 will be forwarded to IP address 192.168.1.50 on the local network.
There are a few things to consider. You don't want IP addresses changing or this will solution stop working. So generally you will also configure the router to always give that device the same local IP address - this is known as a "static" IP address. Similarly you also want your public address to be the same... if you restart your router you may be assigned a different public IP address. Your ISP can usually (not always) assign a static IP to ensure you always get the same public address.
Domain names
This is just a nicer way to point to an IP address. You can register a "domain name" and then use that instead of the public IP to connect to a service on the Internet. So www.google.com instead of 172.217.24.36 for example.
Sometime an ISP is not able to provide a static public IP address, so that's where "dynamic DNS" comes in. Basically you register in a similar way but this time if your IP address changes then you tell the Dynamic DNS that is has changed so it continues to work even with the new public IP address.
This is a very simplistic view of things, but hopefully gives you an overview.
Port Forwarding is used for connections coming from clients on the Internet to servers on your LAN. For outgoing connections (client on your LAN to server on the Internet) the router uses NAT: Network Address Translation. The router remembers what connections have been made and traffic coming back for that connection get routed to the right LAN address.
An alternative to Port Forwarding is "UPnP" (Universal Plug-and-Play). The server on the LAN sends a message to the router to automatically set up port forwarding. This feature has security problems so it is not offered or disabled by default on many routers.
Thanks for responding, It's really helped me out!
However, I have 2 questions and was wondering If any one could answer them.
W3Schools offers free subdomains (E.g. arduino-control.w3spaces.com) would I be able to connect that to Google Domains? I can't seem to find the answer on their website...
Will what I'm doing (connecting IP to domain) cause any security issues? For example would it make me more susceptible to cyber attacks?
https://www.w3schools.com/spaces/
They appear to be offering a subdomain name and server space on their servers. You don't 'own' the domain so you can't transfer management to Google Domains. You could probably register a domain with Google Domains (or any other domain registrar) and point it to your w3schools server space. You can get a free subdomain from several Dynamic DNS server companies.
If an IP address is reachable from the public internet, it WILL be attacked. Adding a name to it to make it easier for a human to remember won't make it much more subject to attack unless someone is targeting you, specifically.