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.

"WEBVTTKind: captionsLanguage: enhello everybody and welcome to another linux for programmers tutorial video in this video i'm going to be showing you how to connect a domain to your lenode server now the reason you would want to do this is so that you don't actually have to navigate to your website by typing in the ip address of a machine instead you're going to type in a domain and that domain is going to be connected to the server such that it knows to kind of ask the server for the website and that's where the requests are going to be sent to so anyways i'm going to be showing you how to do that i'm also going to show you how to make it so your website will run once you close this ssh window so you may have noticed that when you ran that unicorn command previously in the last video as soon as you close this ssh window your website stopped working so to make this website continue to work there's kind of a little trick that we have to do which i will show you in one second anyways we'll get into that after a quick word from the sponsor of this video and this series which is lenode lenode makes it extremely easy for developers to start up linux machines with their one-click applications and great support the node has support for domains as you're going to see in this video support for kubernetes docker and a bunch of other technologies that you're going to be using a lot as a programmer so get started with lenod today by hitting the link in the description and claiming a hundred dollars in free credit when you sign up with a new account all right so let's get into it the first thing i'm going to show you is how you can run this website even when your ssh window is closed so by default when you type a command and you're ssh into a linux machine that command or that process whatever it is is attached to your ssh client to your ssh instance so as soon as you close the ssh window whatever was running is just going to stop running so to fix this you need to use a prefix before this command which is called screen now i won't get into a ton of detail here but what screen will do is detach the process from the ssh window such that when you close the ssh window it's still going to be running so all i have to do if i want to make this website live when this ssh window is closed is type and then the or should run my website you can see it's listening on localhost and now if i go here and i refresh all is good now watch when i close my ssh window so i'm going to close the session you can see this is my website i keep refreshing and it is still working if we had not have typed screen then as soon as i close the ssh window this website would stop working all right so now we need to connect a domain to our lenove so to do this we first need to purchase a domain now i actually have a domain this is called timeoutwithtim.net i had a podcast that i did a while ago that was called timeout with tim and while i purchased this domain and actually never had any use for it i never ended up using it so this is a good purpose for it i can use it in this video but yeah you do need a domain unfortunately i can't give you a domain for free so you will need to purchase one if you want to follow along although i'm kind of going to assume if you're watching this you probably already have a domain all right so assuming you have a domain purchase it on whatever website you want i'm using namecheap that's just what i've used for a bunch of my domains but you can use godaddy or any other domain provider that you want and you need to go into the settings of your domain so go into the settings and then what you're going to look for is name servers now it's hard for me to tell you where this is going to be because this will depend on the website that you're on but if you are in namecheap here then you should just be able to go to domain and then name servers and it's you know pretty obvious where it is so what we need to do here first is we need to change our dns to be custom dns so you might have like if you're on namecheap it might be basic dns might be web hosting dns whatever change it to custom dns the reason for this is we want to point this domain to our lenode server so lenode has these name servers that we need to add as name servers for our domain so that we can manage our domain from lenod so you'll see that in one second but the name servers that we need to add here are ns1 dot lenode.com ns2. and then all the way up to five so ns3 dollar node.com and s4.lenode.com and then finally ns5.lenode.com so once we have these name servers i'm going to press this little check mark to save these and you're going to notice that we're going to get some notification that pops up here in a second that says this might take up to 48 hours to take effect now it almost never takes this long for your name servers to resolve or for your uh your domain name to resolve but sometimes it can take up to two days so just keep in mind that this is not going to be instant and if your domain is not working immediately just be patient it will work it's just going to take you know a few hours or potentially a few days so i won't be able to show you the finished product in this video because well we're gonna have to wait you know a day or two for this to resolve uh but you get the idea so once we've added these name servers what we're gonna do is head over here to lenode and we are now going to add our domain so the reason we added these name servers is so that now we can manage our domain from lenode so now we head over to lenode after we've added those five name servers to our domain we're going to press create a domain from the domains tab so press create a domain and then what you're going to do is you're going to type in the name of your domain so in this case mine was timeoutwithtim.net now it requires that you put an email in here so just put whatever email you want i will just put my business one so tim techwithtim.net all right so now i'm going to press create domain now notice that you can insert default records from one of your nodes so if you want to do this this is probably the easiest way you can press insert default records for one of myla nodes then you can select the node so i'm going to select flask app and then press create domain but if you know how to insert your own a records you don't have to do this if you have no idea what i'm talking about with a records then probably follow along with this step so we will continue in one second but i need to quickly thank the other sponsor of this video which is algo expert algo expert is the best platform to use from preparing for your software engineering coding interviews they have over 120 coding interview questions and each and every one of those questions have full video solutions detailed walkthroughs conceptual overviews and code walkthroughs get started with algo expert today by hitting the link in the description and using the code tech with tim for a discount on the platform alright so you can see that our domain is now set up and notice that we have all of these a records that were automatically added for us so what an a record is is just an address so that's all it stands for it stands for address so you have a host name which is like your domain for example and then that is going to point to a specific address so in this case we're pointing to the address of our lenode server so we're saying timeout with tim needs to point to and then whatever this ip address is that's going to be the ip you can see right here of our website previously or of the server that we are running the website on now it's important that you have an a record for both the ipv4 address and the ipv6 address and really the only two you're going to need are these two right here that were automatically added for us now you also of course can add www and mail i'm not going to talk about these ones because we don't really need them but if i go to add an a record here this is how you can add your own custom a records so let's say you want to add something like a sub domain if you wanted to add a sub domain then what you would have to do is go into the a records here and you would have to type the name of your subdomain so say like api or something then the ip address that you wanted to point it to so that would mean if you went to api.timeoutwithtim.net that would point to and then whatever the ip address is that you put in here now you also can point subdomains to different servers you can point this domain to different servers there's a lot of things you can do here i'm not an expert on a records and doing all this kind of stuff so i'm going to admit talking about it too much but this is the basic idea behind adding a domain so this is actually as simple as it is you just have to point the domain to lenode so you have to add all of the name servers in here you have to wait for this to resolve and then you have to add the domain on the node and then you can manage it from here so you can see we have our primary domain we have our ns record so our name servers we have our mail records and our a records so that's all i have for you i apologize that there wasn't a ton of content in this video but that's all i need to show you to add a domain so if you want to add a domain to a node you point the domain to lenode by adding the name servers you then come in here create a new domain and then you manage the domain by changing its a records in any of the other settings that you want now again you can just use that really simple shortcut that i showed you so you press you know set up the a records automatically and then it will just add all these in for you you just wait a few hours then you should be good to go so anyways i hope you guys enjoyed if you did make sure to leave a like subscribe to the channel and i will see you in another youtube video\n"