To configure a MikroTik Cloud Hosted Router (CHR) as a VPN/NAT gateway on WebNZA, follow these steps:
-
Deploy MikroTik CHR on Webnza:
-
Create a New Server:
- Log in to your WebNZA account.
- Navigate to the server creation section and select the appropriate server specifications for your needs.
- Choose MikroTik CHR as the operating system image.
- Select additional options as needed, such as data center location, additional storage, etc.
- Add SSH keys for secure access.
- Finalize and create the server.
-
Access the Server:
- Once the server is created, note its public IP address.
- SSH into the server using the provided IP address:
ssh root@your_server_ip
-
Create a New Server:
-
Basic MikroTik CHR Configuration
-
Login to MikroTik:
-
After accessing the server via SSH, log in to MikroTik using the default username (
admin
) and no password (you will be prompted to set a new password).
-
After accessing the server via SSH, log in to MikroTik using the default username (
-
Update the RouterOS:
- It's good practice to ensure the system is up-to-date:
/system package update install
-
Configure Initial Settings:
- Set up the basic settings like hostname, DNS, and NTP.
/system identity set name=MyCHR /ip dns set servers=8.8.8.8,8.8.4.4 /system ntp client set enabled=yes primary-ntp=1.1.1.1 secondary-ntp=1.0.0.1
-
Login to MikroTik:
-
VPN Configuration
We'll set up an L2TP/IPsec VPN.
-
Configure IPsec:
-
Set up IPsec peer and proposal:
/ip ipsec proposal set default auth-algorithms=sha256 enc-algorithms=aes-256-cbc /ip ipsec peer add address=0.0.0.0/0 exchange-mode=main-l2tp generate-policy=port-override secret=your_secret_password
-
Set up IPsec peer and proposal:
-
Configure L2TP:
-
Set up the L2TP server:
/interface l2tp-server server set enabled=yes use-ipsec=yes ipsec-secret=your_secret_password default-profile=default
-
Set up the L2TP server:
-
Create VPN User:
-
Add a VPN user:
/ppp secret add name=user1 password=your_password profile=default-encryption service=l2tp
-
Add a VPN user:
-
Configure IPsec:
-
NAT Configuration
-
Enable NAT:
-
Configure NAT to masquerade the traffic:
/ip firewall nat add chain=srcnat action=masquerade out-interface=ether1
-
Configure NAT to masquerade the traffic:
-
Firewall Configuration:
-
Ensure firewall rules allow VPN traffic:
/ip firewall filter add chain=input protocol=udp dst-port=500,1701,4500 action=accept place-before=1 /ip firewall filter add chain=input protocol=ipsec-esp action=accept place-before=1 /ip firewall filter add chain=input protocol=tcp dst-port=1723 action=accept place-before=1 /ip firewall filter add chain=input protocol=gre action=accept place-before=1 /ip firewall filter add chain=input protocol=udp dst-port=1701 action=accept place-before=1
-
Ensure firewall rules allow VPN traffic:
-
Enable NAT:
-
Connecting to the VPN
-
Client Configuration:
- Configure your VPN client (Windows, macOS, Linux, etc.) to connect to the VPN server using the public IP address of your WebNZA server.
- Use the L2TP/IPsec settings with the shared secret and the username/password created earlier.
-
Client Configuration:
-
Testing and Finalizing
-
Test Connectivity:
- Verify that you can connect to the VPN from a remote client.
- Check if the VPN client can access the internet through the NAT gateway.
-
Secure the CHR:
- Change the default admin password.
- Add firewall rules to secure the CHR from unauthorized access.
-
Backup Configuration:
-
Regularly backup your MikroTik configuration:
/export file=backup
-
Regularly backup your MikroTik configuration:
-
Test Connectivity:
Here's a consolidated example of the commands:
/system identity set name=MyCHR
/ip dns set servers=8.8.8.8,8.8.4.4
/system ntp client set enabled=yes primary-ntp=1.1.1.1 secondary-ntp=1.0.0.1
/system package update install
/ip ipsec proposal set default auth-algorithms=sha256 enc-algorithms=aes-256-cbc
/ip ipsec peer add address=0.0.0.0/0 exchange-mode=main-l2tp generate-policy=port-override secret=your_secret_password
/interface l2tp-server server set enabled=yes use-ipsec=yes ipsec-secret=your_secret_password default-profile=default
/ppp secret add name=user1 password=your_password profile=default-encryption service=l2tp
/ip firewall nat add chain=srcnat action=masquerade out-interface=ether1
/ip firewall filter add chain=input protocol=udp dst-port=500,1701,4500 action=accept place-before=1
/ip firewall filter add chain=input protocol=ipsec-esp action=accept place-before=1
/ip firewall filter add chain=input protocol=tcp dst-port=1723 action=accept place-before=1
/ip firewall filter add chain=input protocol=gre action=accept place-before=1
/ip firewall filter add chain=input protocol=udp dst-port=1701 action=accept place-before=1
/export file=backup
By following these steps, you should have a MikroTik CHR configured as a VPN/NAT gateway on Webnza