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.
<pre>root@gateway:/# sysctl -p net.ipv4.ip_forward = 1</pre>next i applied iptables rules like this:
<pre>iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A FORWARD --in-interface eth1 -j ACCEPT</pre>Relevant informations for the gateway droplet
<pre>root@gateway:/etc/ufw# ifconfig eth0 addr:107.170.8.148 Bcast:107.170.8.255 Mask:255.255.255.0 eth1 addr:10.128.169.173 Bcast:10.128.255.255 Mask:255.255.0.0 lo inet addr:127.0.0.1 Mask:255.0.0.0
root@gateway:/# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 107.170.8.1 0.0.0.0 UG 0 0 0 eth0 10.128.0.0 * 255.255.0.0 U 0 0 0 eth1 107.170.8.0 * 255.255.255.0 U 0 0 0 eth0
root@gateway:/# iptables-save
*mangle :PREROUTING ACCEPT [478:36001] :INPUT ACCEPT [296:23936] :FORWARD ACCEPT [173:11525] :OUTPUT ACCEPT [305:45020] :POSTROUTING ACCEPT [478:56545] COMMIT
*filter :INPUT ACCEPT [214:17088] :FORWARD ACCEPT [40:3324] :OUTPUT ACCEPT [248:36052] -A FORWARD -i eth1 -j ACCEPT COMMIT
*nat :PREROUTING ACCEPT [41:2538] :INPUT ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] -A POSTROUTING -o eth0 -j MASQUERADE COMMIT
Then i added static route for eth1 interface like this
ip route add default via 10.128.169.17 dev eth1
Here is the relevant output.
<pre>eth1 addr:10.128.169.172 Bcast:10.128.255.255 Mask:255.255.0.0 lo addr:127.0.0.1 Mask:255.0.0.0
root@gwclient:/etc# ip route default via 10.128.169.173 dev eth1 10.128.0.0/16 dev eth1 proto kernel scope link src 10.128.169.172</pre>Traceroute output from gwclient droplet
<pre>root@gwclient:/etc# traceroute 212.62.32.1 traceroute to 212.62.32.1 (212.62.32.1), 30 hops max, 60 byte packets 1 10.128.169.173 (10.128.169.173) 0.611 ms 0.609 ms 0.622 ms 2 * * * 3 * * * </pre>From traceroute outoput its obvious that that gateway on 10.128.169.173 (eth1 interface on gateway droplet) is setup correctly.
And finally here are tcpdump outputs from gateway droplet on both interfaces
<pre>eth0 16:22:24.088123 IP 107.170.8.148 > ns1.ptt.rs: ICMP echo request, id 2099, seq 210, length 64 16:22:23.202942 IP ns1.ptt.rs > 107.170.8.148: ICMP echo reply, id 2099, seq 209, length 64
eth1 16:23:26.584029 IP gwclient > ns1.ptt.rs: ICMP echo request, id 2099, seq 272, length 64 16:23:26.707862 IP ns1.ptt.rs > gwclient: ICMP echo reply, id 2099, seq 272, length 64</pre>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
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
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.
I was able to work this around by using ipip tunnel:
Gwclient.eth1 ===== eth1.Gateway
on Gwclient:
on Gateway:
After that, you can set ip routes to ipip0 on Gwclient, that way they won’t be dropped by DO’s underlying network.
I don’t think we do but passed it onto our tutorials group so they can look into getting something.
They did suggest https://www.digitalocean.com/community/tutorials/how-to-install-tinc-and-set-up-a-basic-vpn-on-ubuntu-14-04 as an alternative that might work better for your situation.
@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.
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.