Websites & Hosting

Self-Hosting a Website From Home

Check your connection, set up a home web server safely, handle changing addresses and decide whether a tunnel is better.

Key takeaways

  • Check first that your provider's terms allow running a server and that your connection can receive incoming connections.
  • Carrier-grade NAT blocks ordinary port forwarding, and a tunnel service or a public IPv6 address may get around it.
  • Expose only the web ports, keep the server separate from your other devices and update it automatically.
  • Home addresses often change, so use dynamic DNS or a tunnel that does not depend on your address.
  • Keep backups away from the house, because one fire, theft or disk failure can take everything.

You can host a website from home on an old computer or a small single-board machine. You need a connection that can accept incoming traffic (or a tunnel service that works around that), a name that points to it, a web server, HTTPS and a habit of applying updates. For learning and personal projects it is rewarding. For anything a business depends on, rented hosting is usually the safer choice.

The main costs are time and responsibility. You become the data center, the network team and the person who answers when it stops.

Before you start

Read your terms of service. Some residential plans restrict running public servers. Business plans often allow it and may include a fixed address.

Check your upload speed. Visitors download what you upload. A page of 2 megabytes (16 megabits) over a 10 megabit per second upstream link takes at least 1.6 seconds for one visitor with nothing else using the line, and simultaneous visitors share it.

Check for carrier-grade NAT. Compare the WAN address shown in your router with the address an outside service reports for you. If they differ, and especially if the router's WAN address falls in 100.64.0.0/10 or a private range, your provider or another device is translating addresses upstream. Carrier-grade NAT explains why ordinary port forwarding then fails.

Think about privacy. Pointing a domain straight at your home reveals your connection's public IP address to anyone who looks, along with a rough location.

Choose how traffic reaches you

How will visitors reach a home server?
Is the site only for you and your household? YES Keep it off the public internet; use a VPN for remote access. 1 NO Do you have a public IPv4 address on your router? YES Forward ports 80 and 443 and use dynamic DNS if it changes. 2 NO Do you want to hide your home address or are you behind CGNAT? YES Use a tunnel service or a small rented relay. 3 NO Are your visitors all on IPv6-capable networks? YES Publish an AAAA record and allow it through the firewall. 4 NO Rent hosting instead A small server or static host avoids the obstacles. Is the site only for you and your household? 1 IF YES Keep it off the public internet; use a VPN for remote access. NO Do you have a public IPv4 address on your router? 2 IF YES Forward ports 80 and 443 and use dynamic DNS if it changes. NO Do you want to hide your home address or are you behind CGNAT? 3 IF YES Use a tunnel service or a small rented relay. NO Are your visitors all on IPv6-capable networks? 4 IF YES Publish an AAAA record and allow it through the firewall. NO Rent hosting instead A small server or static host avoids the obstacles.

A tunnel service has your server open an outbound connection to a provider, which accepts visitors and passes requests back through it. No ports need opening on your router. The trade-off is reliance on that provider, which can typically see the traffic it relays when it handles the encryption.

Set up the server

Any computer that can run a current Linux distribution will do. Small, low-power machines keep the electricity bill and noise down. Use wired Ethernet, and give the machine a fixed local address with a DHCP reservation in your router.

On a Debian or Ubuntu system, installing a web server takes two commands:

sudo apt update
sudo apt install nginx

Other distributions use different package managers. From another device on your network, browse to the server's local address, such as http://192.168.1.50/. You should see a welcome page. Put your files in the site's document root, which is set in the server configuration.

For HTTPS you need a certificate. Free automated certificate authorities issue them, and a client program renews them without your help; see Let's Encrypt and ACME. Some web servers, such as Caddy, handle this automatically.

Open the router carefully

Publishing a home server with port forwarding
1 Reserve a local address The server keeps the same private IP after restarts. 2 Harden the server Update it, turn on its firewall and remove unused services. 3 Forward 80 and 443 The router sends web traffic to that one machine. 4 Point your name Create DNS records for the public address. 5 Get a certificate Enable HTTPS and automatic renewal. 6 Test from outside Try over mobile data, not your home Wi-Fi. Reserve a local address The server keeps the same private IP after restarts. 1 Harden the server Update it, turn on its firewall and remove unused services. 2 Forward 80 and 443 The router sends web traffic to that one machine. 3 Point your name Create DNS records for the public address. 4 Get a certificate Enable HTTPS and automatic renewal. 5 Test from outside Try over mobile data, not your home Wi-Fi. 6

Forward only the ports the website needs. Do not use the router's "DMZ" setting, which exposes every port on the machine. Do not publish your router's own administration page. Port forwarding covers the steps and the risks.

Testing from inside the house can mislead, because some routers do not loop traffic back to their own public address. Mobile data gives a true outside view.

Point a name at a changing address

Most home addresses change from time to time. Dynamic DNS solves this: a small program on the router or server notices a new address and updates your DNS record. Keep the record's time to live short, a few minutes, so the change spreads quickly. Many routers have a client built in, and many DNS providers offer an API for scripts.

For your own domain, a CNAME from www to the dynamic name is a common arrangement. The bare domain needs address records or a provider feature that imitates them.

Secure it

A public server is probed by automated scanners soon after it appears. Plan on it.

  • Turn on automatic security updates for the system.
  • Run a host firewall that allows only what you serve.
  • Keep remote administration off the public internet. If you must allow SSH from outside, use keys, disable password logins and see SSH security basics.
  • Place the server on a separate network or VLAN if your router supports it, so a compromise does not reach your laptops and cameras.
  • Keep any web application and its plugins patched, or serve static files and avoid the problem.
  • Read the logs now and then. Reading server logs shows what normal and abnormal look like.

On Ubuntu with the ufw firewall, a minimal rule set for a web server administered from the local network could be:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp
sudo ufw enable

Adjust the subnet to match yours, and keep a keyboard and screen handy in case you lock yourself out.

Keep it running and recoverable

Power cuts, router restarts and full disks are the usual outages. Set the computer to start again when power returns. A small uninterruptible power supply can ride out brief interruptions for both server and router. Use an outside uptime monitor to tell you when it is down.

Back up the content, configuration and database to a location outside your home. Then rebuild from the backup once, onto a spare disk, to confirm that it works.

Containers, apps and what to host first

Start small. A folder of static pages teaches you DNS, forwarding and certificates with very little that can be exploited. Add an application later, once updates and backups are routine.

Many self-hosted programs are distributed as container images, which package an application with its dependencies. Containers make installation and removal tidy. They do not update themselves by default, and a published container port can bypass host firewall rules you assumed would cover it, particularly with Docker on Linux. Check what is actually reachable from another machine after every change.

Whatever you install, note its version, where it keeps data and how you upgrade it. A text file in your backup is enough. Applications with accounts deserve extra care: change default credentials, turn off open registration unless you want strangers signing up and enable two-factor sign-in if offered.

Counting the cost

Electricity is easy to estimate. A machine drawing an average of 10 watts uses about 7.3 kilowatt-hours in a 730-hour month, while one drawing 100 watts uses about 73. Multiply by the price on your own bill. An old desktop tower that was free to acquire can be the expensive choice over a few years.

Add the domain renewal, any tunnel or relay fee, a backup destination and replacement disks. Then compare the total with a small rented server that includes power, cooling and a fast, symmetrical connection.

Email is a separate, harder job

Hosting a website at home does not mean hosting mail there. Residential address ranges are widely distrusted by mail filters, many providers block outbound port 25, and reverse DNS is usually not yours to set. Use an outside mail service, including for messages your site's forms send. Running your own mail server explains the obstacles.

Looking after it over the months

A home server tends to work well for a while and then be forgotten. A monthly routine of a few minutes prevents most surprises:

  • confirm that updates have been installing and reboot if the system asks,
  • check free disk space and the disk's health reports,
  • look at the certificate's expiry date,
  • review which ports your router forwards, and delete rules you no longer need,
  • check that the latest backup exists and open a file from it, and
  • remove services and user accounts you stopped using.

Also check that your operating system release still receives security updates. When it approaches the end of support, plan the upgrade or rebuild. If you can no longer keep up, take the site offline and close the forwarded ports. An abandoned public server is a risk to you and to others, since compromised machines are commonly put to work attacking third parties.

When it does not connect

Work from the inside out.

  1. Does the page load on the server itself, for example with curl -I http://localhost/?
  2. Does it load from another device at the local address? If not, check the host firewall.
  3. Does DNS return the address you expect? Compare it with your router's current WAN address.
  4. From mobile data, does the connection time out? Suspect forwarding rules, carrier-grade NAT or a blocked port.
  5. Does the browser show a certificate warning? Check that the certificate matches the name and has renewed.

Is it worth it?

Home hosting is a fine way to learn networking and Linux, to serve a family photo page or to run a project you can afford to see offline. The electricity, hardware and hours often add up to more than a basic hosted plan, and a static hosting service will usually be quicker for visitors. Choose home hosting because you value the control and the lessons, and keep anything important somewhere with spare power and someone else on duty.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Websites & Hosting →

Latest news on this topic