Nat gateway on digital ocean's droplet possible ?

May 19, 2014 11.5k views
Digital ocean introduced private network feature in newyork 2 region. I've created 2 droplets (gateway and gwclient both ubuntu 13.10 x64) with private network feature enabled. Droplet "Gateway" should act as a NAT Gateway router. Another droplet "Gwclient" should use "gateway" droplet to communicate with the outside world. My idea was to use iptables to accomplish this scenario. First of all i've disabled firewalls on both droplets On gateway droplet ip forwarding is enabled.
root@gateway:/# sysctl -p 
net.ipv4.ip_forward = 1
next i applied iptables rules like this:
iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE 
iptables -A FORWARD --in-interface eth1 -j ACCEPT
Relevant informations for the gateway droplet
root@gateway:/etc/ufw# ifconfig 
eth0 addr: Bcast: Mask: 
eth1 addr: Bcast: Mask: 
lo inet addr: Mask:

root@gateway:/# route 
Kernel IP routing table 
Destination Gateway Genmask Flags Metric Ref Use Iface 
default UG 0 0 0 eth0 * U 0 0 0 eth1 * U 0 0 0 eth0

root@gateway:/# iptables-save 
# Generated by iptables-save v1.4.18 on Sun May 18 16:03:33 2014 
:INPUT ACCEPT [296:23936] 
:FORWARD ACCEPT [173:11525] 
:OUTPUT ACCEPT [305:45020] 
# Completed on Sun May 18 16:03:33 2014 
# Generated by iptables-save v1.4.18 on Sun May 18 16:03:33 2014 
:INPUT ACCEPT [214:17088] 
:FORWARD ACCEPT [40:3324] 
:OUTPUT ACCEPT [248:36052] 
-A FORWARD -i eth1 -j ACCEPT 
# Completed on Sun May 18 16:03:33 2014 
# Generated by iptables-save v1.4.18 on Sun May 18 16:03:33 2014 
# Completed on Sun May 18 16:03:33 2014
On a gwclient droplet i disabled eth0 interface and left only private network interface. Then i added static route for eth1 interface like this ip route add default via dev eth1 Here is the relevant output.
eth1 addr: Bcast: Mask: 
lo addr: Mask:

root@gwclient:/etc# ip route 
default via dev eth1 dev eth1 proto kernel scope link src
Traceroute output from gwclient droplet
root@gwclient:/etc# traceroute 
traceroute to (, 30 hops max, 60 byte packets 
1 ( 0.611 ms 0.609 ms 0.622 ms 
2 * * * 
3 * * * 
From traceroute outoput its obvious that that gateway on (eth1 interface on gateway droplet) is setup correctly. And finally here are tcpdump outputs from gateway droplet on both interfaces
16:22:24.088123 IP > ICMP echo request, id 2099, seq 210, length 64 
16:22:23.202942 IP > ICMP echo reply, id 2099, seq 209, length 64

16:23:26.584029 IP gwclient > ICMP echo request, id 2099, seq 272, length 64 
16:23:26.707862 IP > gwclient: ICMP echo reply, id 2099, seq 272, length 64
Everything seems good except i never got reply to gwclinet droplet. tcpdump on eth1 (gwclient) remains empty .Packets never arrive . Is it possible at all to setup a NAT gateway on digital ocean droplet. Is it prohibited / blocked or i am doing something wrong. The procedure for building a nat router , i've described above, is a pretty standard . Best regards
4 Answers
Hi there -- Unfortunately, this configuration will not work due to the anti-spoofing ruleset we have in place to protect your droplets. You're correct that everything works on the way out, but where this gets caught is in the return path from the gateway droplet to your private IP only droplet. Since it the gateway box is attempting to send a packet that has a different source address from itself, it will not be allowed through. Please let us know if you have further questions.
You can use a proxy or nat setup on your gateway droplet to achieve this. (traffic leaving gateway droplet natting to the interface ip) The trick is the source address must always stay the droplet assigned ip. As Neal mentioned, it's a security thing and we have to do it.

@bryan I have setup a nat between eth0 and eth1 but I'm still hitting the same problem. Do you have a link or an example of the nat or proxy you are talking about in your comment.

I don't think we do but passed it onto our tutorials group so they can look into getting something.

They did suggest as an alternative that might work better for your situation.

by Mitchell Anicas
In this tutorial, we will go over how to use Tinc, an open source Virtual Private Network (VPN) daemon, to create a secure VPN that your servers can communicate on as if they were on a local network. We will also demonstrate how to use Tinc to set up a secure tunnel into a private network. We will be using Ubuntu 14.04 servers, but the configurations can be adapted for use with any other OS.
Have another answer? Share your knowledge.