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:184.108.40.206 Bcast:220.127.116.11 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 18.104.22.168 0.0.0.0 UG 0 0 0 eth0 10.128.0.0 * 255.255.0.0 U 0 0 0 eth1 22.214.171.124 * 255.255.255.0 U 0 0 0 eth0
*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 126.96.36.199 traceroute to 188.8.131.52 (184.108.40.206), 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
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 .
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!
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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $100 of credit to try our products over 60 days!