Disclaimer: Instructions are accurate as of 05/30/2024. Mikrotik is not a product or partner of DigitalOcean. Users are responsible for verifying if all settings are correct.
Using a NAT Gateway to provide a single egress IP for all your deployments in DigitalOcean eliminates the need to allow-list multiple IP addresses for the end-users. This detailed tutorial will teach you how to configure Mikrotik’s Cloud Hosted Router as a NAT Gateway in DigitalOcean. You can leverage this setup to configure the IPSec tunnel between DigitalOcean and other clouds.
You will need the following:
Download the Cloud Hosted Router(CHR) from https://mikrotik.com/download. Select the “Raw disk image” for the latest Stable release and unzip the image to a local folder on your system. You should end up with a .img
extension file, for example-chr-7.14.3.img
Log in to your DigitalOcean Control Panel
Navigate to Backups & Snapshots -> Custom Images.
Upload the CHR image as a custom image. Select “Unknown” for the distribution type and select the region where you would like to deploy the droplet.
The image importer will not display a progress bar during this process. Please allow at least 20 minutes for the CHR image to be imported, validated, and made available for the region selected on the platform.
Mikrotik recommends a minimum of 1GB of RAM. For this example, you can use a $6 Droplet (s-1vcpu-1gb).
When creating the droplet, select an SSH key to allow the customer image to be created. This SSH key will not be added to the Mikrotik configuration, but it’s required for droplet creation.
Once the CHR Droplet is created, it will enable a completely unsecured firewall instance for easy access. You must secure this image by logging into the newly created droplet and configuring a password and basic security settings. Use SSH to configure the initial setup. There are multiple ways to log in for the initial setup (SSH, Web UI, Winbox [Desktop App]).
For this tutorial, you will use SSH to configure the initial configuration.
a. Login with your favorite SSH client as the username “admin” for example, using openssh
:
b. Accept the Mikrotik License from the SSH and configure a secure password for access to the firewall.
c. Once the password is configured, you will see the “Password changed” confirmation and have access to the Mikrotik command line :
d. Let’s configure a secure account and disable the default admin account. After login in with the new account and making sure it has full access then, disable the default admin account:
e. Let’s configure the interface names:
f. By default, CHR images come with no firewall rules. To secure the firewall, you need to add some basic rules and rename interfaces for ease of use, adding the droplet’s public IP address to the firewall’s allow-list
.
g. Let’s configure the firewall DNS to use DigitalOcean DNS resolvers:
h. You also need to configure the droplet VPC IP address on the firewall. This can be retrieved from the droplet networking panel. You can use the following commands from the firewall console to do so.
i. To allow VPC traffic to access the internet, enable NAT:
j. To make our installation more secure, let’s disable some services that are usually not required in the cloud for a more secure droplet:
k. By default, the CHR router comes with a free trial License; once you have your gateway fully working to activate an already purchased license, you will need to log in with your Mikrotik Portal credentials to activate it:
Once you configure the Droplet as NAT Gateway using Mikrotik’s CHR, configure the backend droplets to set the static route pointing to the NAT Gateway and verify the NAT Gateway setup as detailed in the How to Configure a Droplet as a VPC Gateway guide.
In this tutorial, you learned how to use Mikrotik’s Cloud Hosted Router image to configure a DigitalOcean Droplet as a NAT Gateway. By leveraging this setup, you can utilize a single egress NAT Gateway for all your resources in DigitalOcean, thus avoiding the need to allow-list multiple egress IPs. As detailed here, this setup can be extended to establish IPsec tunnels between clouds, providing a secure connection for inter-cloud communications.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!