If you create an EC2 instance and don't want to rely on its public IP address for SSH access, Tailscale provides a simple alternative.
Instead of connecting directly to the EC2 public IP, you connect to the instance through your private Tailscale network.
1. Create an EC2 Instance
Create your EC2 instance as usual.
You can run it without assigning a public IPv4 address if you have another way to initially install Tailscale, such as EC2 User Data or AWS Systems Manager.
2. Install Tailscale
On the EC2 instance, install Tailscale according to your Linux distribution.
For Amazon Linux, for example:
sudo yum install tailscale
Start the service:
sudo systemctl enable --now tailscaled
Then authenticate the instance:
Follow the authentication URL and add the EC2 instance to your Tailscale network.
3. Install Tailscale on Your Computer
Install Tailscale on your laptop/desktop and sign into the same Tailscale account.
Once both machines are connected, they can communicate through Tailscale.
4. Get the EC2 Tailscale IP
On the EC2 instance:
You'll get an address such as:
You can then SSH into the instance:
5. Use MagicDNS
Instead of remembering the Tailscale IP, enable MagicDNS in Tailscale.
You can then connect using the machine's hostname:
This is much more convenient when you have multiple servers.
The Result
Your setup becomes:
Your Laptop
│
│ Tailscale
│
▼
EC2
Rather than:
Your Laptop
│
│ Public Internet
│
▼
Public EC2 IP
│
▼
EC2
Tailscale effectively lets you treat your EC2 instance as another private machine on your network, making SSH and other internal services accessible without relying on the EC2 public IP.
Loading article