This guide will walk you through the steps to set up a secure connection to your home PC from an external network. The setup uses a TOTOLINK router as an example.
- A router that supports Port Forwarding (e.g., TOTOLINK).
- A Linux system running on your home PC (e.g., Ubuntu).
- A DuckDNS account to bind your dynamic IP to a fixed domain name.
First, configure Port Forwarding on your router to allow external access to your home PC.
- Open your browser and access the router's admin page (usually 192.168.0.1).
- Log in and navigate to the Port Forwarding settings.
- Add the following rule:
- External Port: 2222
- Internal IP: 192.168.1.100
- Internal Port: 22
- Protocol: TCP
Run the following command on your home PC to find its internal IP address:
ip addrLook for an IP address in the format 192.168.x.x. This is your Internal IP.
Next, install and enable the SSH service on your home PC to allow remote access.
- Update your system packages:
sudo apt update
- Install the OpenSSH server:
sudo apt install openssh-server
- Enable and start the SSH service:
sudo systemctl enable ssh sudo systemctl start ssh
If your home network uses a dynamic IP (which changes whenever your router reconnects), use DuckDNS to bind it to a fixed domain name.
- Go to the DuckDNS website and create an account.
- Log in and create a subdomain (e.g.,
myhomepc). Afterward, you will have a domain likemyhomepc.duckdns.org. - Note down your DuckDNS token and set up a cron job to automatically update your IP:
Replace
echo "*/5 * * * * curl -k 'https://www.duckdns.org/update?domains=myhomepc&token=YOUR_TOKEN&ip='" | crontab -
YOUR_TOKENwith your DuckDNS token.
After completing all the steps, test the remote connection from an external network.
Use the following command to connect:
ssh username@myhomepc.duckdns.org -p 2222- Replace
usernamewith your home PC's username. - If everything is set up correctly, you should be able to connect to your home PC successfully!
- Ensure that your router and computer firewalls allow connections on port 2222.
- For security, use a strong password or other security measures to protect your SSH service.
By following these steps, you should now be able to securely connect to your home PC from anywhere. If you encounter any issues, double-check each step or review error logs for troubleshooting.