{"id":244,"date":"2007-07-09T09:46:56","date_gmt":"2007-07-09T07:46:56","guid":{"rendered":"http:\/\/www.lucas-nussbaum.net\/blog\/?p=244"},"modified":"2007-07-09T09:46:57","modified_gmt":"2007-07-09T07:46:57","slug":"easy-migration-of-a-service-to-another-totally-different-host-with-iptables","status":"publish","type":"post","link":"https:\/\/www.lucas-nussbaum.net\/blog\/?p=244","title":{"rendered":"Easy migration of a service to another, totally different host with iptables"},"content":{"rendered":"<p>I&#8217;m tired of googling for this every time I need it, so I&#8217;m blogging about it.<\/p>\n<p>Q: How can one redirect all connections to hostA:portA to hostB:portB, where hostA and hostB and in totally different parts of the Internet?<\/p>\n<p>A:<br \/>\n<code>echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward<br \/>\n$IPT -t nat -A PREROUTING -p tcp --dport portA -j DNAT --to hostB:portB<br \/>\n$IPT -A FORWARD -i eth0 -o eth0 -d hostB -p tcp --dport portB -j ACCEPT<br \/>\n$IPT -A FORWARD -i eth0 -o eth0 -s hostB -p tcp --sport portB -j ACCEPT<br \/>\n$IPT -t nat -A POSTROUTING -p tcp -d hostB --dport portB -j SNAT --to-source hostA<\/code><\/p>\n<p>Connections are masqueraded, that means that, for hostB, all connections are coming from hostA. So be careful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m tired of googling for this every time I need it, so I&#8217;m blogging about it. Q: How can one redirect all connections to hostA:portA to hostB:portB, where hostA and hostB and in totally different parts of the Internet? A: echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward $IPT -t nat -A PREROUTING -p tcp &#8211;dport portA -j DNAT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"0","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,12,7],"tags":[],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-planetdebian","category-planetubuntu","category-technology"],"_links":{"self":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=244"}],"version-history":[{"count":0,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}