The answer by Arjan is good. Technical. I wanted to provide a different flavor answer to help those who are new and struggling to put the picture together in regards to gateways and how packets move back and forth.
Analogy...
You > Letter > Mailbox > Mailman > Post Office Dist > Recipient
|----------------- TX -------------------|
Node > Packet > Transmission > Gateway > Network Server > Application
|----------------- RX -------------------|
Node < Packet < Transmission < Gateway < Network Server < Application
Letter/Packet has an address. The mailman/gateway picks up the letter from your mailbox or whatever mailbox you dropped your letter in. It gets handled all the way to the recipient. If the address is wrong, it wont arrive and you should get notified of that. The recipient can send a letter back to you through the same system.
Whether you're going to utilize the The Things Network or try to build your own private server using something like LoRaServer you will need a gateway within reach of your node/mote/end-device to forward messages back and forth. Think of the different keys in the node's code as the addresses on the letter in the analogy.
You can determine if there's already a TTN gateway in your area on their map page and if there is one in reach of your node, your messages should reach your TTN (assuming you have registered and applied the keys to your node). If there's not a gateway within reach, you can build your own. There's many options to do that.
In regards to configuring the gateway, depending on which library you choose, you typically just need to configure some parameters either in the source code or in a global_conf.json or local_conf.json file.
Here's an example from tinkering with a RFM9X (based on SX1276) and a RPI3 B+ using single_chan_pkt_fwd which btw will not provide responses... keep in mind this is just for tinkering/testing. Both the forwarder and below global_conf.json examples are not plug-n-play and should not be relied on for proper LoRaWan networking. A compliant gateway has 3 radios and can process multiple channels and send/receive at the same time. This example is just receive from node on single channel and is not very reliable but does present configuration. Each of the values depends on the hardware you're using and where you're located... or where the gateway is located such as US, EU, etc... also worth noting that such global_conf.json is not a one size fits all. Different libraries typically have more config options for multiple radios, channels, etc... just FYI.
{
"SX127x_conf": // depending on your hardware/radio this could be something like sx1301..., sx127x...., etc..
{
"freq": 903000000, // depending on whether US (900 range), EU (800 range) or other...
"spread_factor": 7, // look this up
"pin_nss": 10, // wiringpi value = physical pin #24
"pin_dio0": 5, // wiringpi value = physical pin #18
"pin_rst": 21 // wiringpi value = physical pin #29
},
"gateway_conf":
{
"ref_latitude": 0.0,
"ref_longitude": 0.0,
"ref_altitude": 2,
"name": "WHATEVER NAME",
"email": "[email protected]",
"desc": "WHATEVER DESC",
"servers":
[
{
"address": "localhost", // this one is private so localhost, but TTN lookup address
"port": 1700, // this one is private so localhost, but TTN lookup port
"enabled": true
} // you could add more... say you have a private one and TTN
]
}
}
Let's say you're building a node with Arduino device and code. And you use something like LMIC-Arduino library and example sketch. You first have to determine based on the device hardware how to configure the pinmap for the device to even work. Then if you're going to use TTN, you follow any of the many guides to register and get the needed keys that you put into the sketch code. You also have to make sure that you're transmitting on the appropriate frequency and such... to line up with the gateway in your area.