Linux for Programmers #15 - How to Connect a Domain to a Linode Server
**Connecting Your Domain to a Linode Server: A Step-by-Step Guide**
---
### Introduction
Welcome to another Linux for Programmers tutorial video! In this guide, we’ll walk you through how to connect a domain to your Linode server. By doing so, you can access your website using a domain name instead of typing in the server's IP address. This is especially useful for making your website more accessible and professional.
---
### Why Connect a Domain?
When you run a web server on your Linode instance, by default, you might need to type the server’s IP address to access your website. However, using a domain name makes this process much simpler. When someone types your domain in their browser, it will automatically direct them to your Linode server. Additionally, we’ll show you how to ensure your website continues running even after closing the SSH session.
---
### Running Your Website After Closing the SSH Window
By default, when you run a command over an SSH connection, the process is attached to that session. If you close the SSH window, the process stops. To keep your website running, we’ll use the `screen` command. Here’s how:
1. **Open a new terminal window** and connect to your Linode server via SSH.
2. Type `screen` before running your web server command (e.g., `unicorn`). This will detach the process from the SSH session, allowing it to continue even after you close the window.
For example:
```
screen unicorn -D -l
```
After starting the server, you can press **Ctrl + D** to exit the screen session. Your website will remain running.
---
### Purchasing and Configuring Your Domain
To connect a domain to your Linode server, you’ll need to purchase a domain name (e.g., `timeoutwithtim.net`). If you don’t already have one, consider using a reliable domain registrar like Namecheap or GoDaddy.
Once you’ve purchased your domain, you’ll need to configure its DNS settings. Here’s how:
1. **Log in to your domain registrar** and navigate to the DNS management section.
2. Change the DNS type from the default (e.g., "Basic DNS") to **Custom DNS**.
3. Add Linode’s name servers:
- `ns1.linode.com`
- `ns2.linode.com`
- `ns3.linode.com`
- `ns4.linode.com`
- `ns5.linode.com`
These changes can take up to 48 hours to propagate globally, so be patient.
---
### Adding Your Domain to Linode
After setting up your domain’s DNS, you’ll need to add it to your Linode account. Here’s how:
1. **Log in to your Linode dashboard**.
2. Navigate to the **Domains** tab.
3. Click on **Create a Domain**.
4. Enter your domain name (e.g., `timeoutwithtim.net`) and select an email address.
5. Choose the type of DNS records you want to create. For simplicity, select **Insert Default Records for One of My Nodes**.
6. Select the node where your website is hosted (e.g., a Flask app) and click **Create Domain**.
Linode will automatically add A records pointing your domain to your server’s IP address.
---
### Understanding DNS Records
DNS records are essential for directing traffic from your domain to your Linode server. Here’s a brief explanation of the key types:
- **A Record**: Maps your domain (e.g., `timeoutwithtim.net`) or subdomains (e.g., `www.timeoutwithtim.net`) to an IP address.
- **NS Record**: Points to Linode’s name servers, which manage your domain’s DNS.
You can manually add A records for subdomains if needed. For example:
- To create a subdomain like `api.timeoutwithtim.net`, go to the A Records section in your Linode dashboard.
- Enter the subdomain name and IP address you want it to point to.
---
### Conclusion
In this guide, we’ve covered how to connect a domain to your Linode server. By purchasing a domain, setting up custom DNS with Linode’s name servers, and creating A records, you can ensure your website is accessible via a domain name. Additionally, using the `screen` command allows your website to run continuously even after closing the SSH session.
If you found this guide helpful, don’t forget to like, subscribe, and share! If you have any questions or tips, feel free to leave them in the comments below.