Scenario: You enable UFW on your Amazon EC2 instance then you log off the system. When you try to connect to that EC2 instance, it doesn’t work because you forget to add SSL (port 22) in the UFW rules.
- We need another running EC2 instance to fix the broken EC2 instance. Please create a new EC2 instance if you don’t have an extra one handy
- Stop the broken EC2 instance and detach the volume
- Attach the volume from the broken EC2 to the other EC2 instance or the one you just created in step #1. For device name, you can use /dev/sdf (you can choose from sdf through sdp)
- Now connect to the new EC2 instance
- Create a folder named fixme (it can be any name you prefer) in your home directory
- Mount the volume to the fixme folder using the following command:
sudo mount /dev/xvdf ~/fixme
Note: newer linux kernels may rename your device to /dev/xvdf (which it did so in my case)
- After successful mount, go to ~/fixme/etc/ufw and edit ufw.conf
- Set enabled=no and save the change
- Unmount the volume using the following command:
sudo umount /dev/xvdf
- Return to AWS console, detach the volume and reattach it to the broken EC2 instance
- Start that broken EC2 instance, it is now no longer broken and you will be able to SSH into that instance like before.
Scenario: You have registered a domain name through NameCheap and you have a running instance of Amazon EC2. Now you want to point the domain to the that EC2 instance.
- Log into NameCheap.com and Amazon Web Services (AWS).
- In your NameCheap.com dashboard, go to “Domain List” and locate the domain name you want to point to AWS. Click the “manage” button.
- On the next page, click “Advanced DNS” tab. Under host records section, you should see 2 entries with “@” and “www”.
- Switch to AWS management console and go to your EC2 instance.
- On the left menu, click “Elastic IPs”
- Click “Allocate new address”.
- Select the new address you just created and click “Associate address”.
- Select your network interface from the drop-down.
- Select the private address from the drop-down and click “Associate”
- The changes in “Elastic IPs” will reflect on public IP address of the EC2 instance.
- Copy the public IP address and public DNS
- Switch back to NameCheap.com, locate entry with “@” symbol, set type to “A Record” and set value to public IP address
- Locate entry with “www”, set type to “CNAME Record” and set value to public DNS
- Apply your changes and you’re done!
You may have to wait a little before the association takes place. I’d say about 5 minutes. Now open your browse and type your domain name, it should now point to your EC2 instance.