{"id":2129,"date":"2015-03-30T15:26:57","date_gmt":"2015-03-30T11:26:57","guid":{"rendered":"http:\/\/sandalov.org\/blog\/?p=2129"},"modified":"2015-03-30T15:27:34","modified_gmt":"2015-03-30T11:27:34","slug":"redirect-outbound-traffic-from-one-host-to-another","status":"publish","type":"post","link":"https:\/\/sandalov.org\/blog\/2129\/","title":{"rendered":"Redirect outbound traffic from one host to another"},"content":{"rendered":"<div class=\"2d836d85a73757df15d0de19d7bef594\" data-index=\"1\" style=\"float: none; margin:10px 0 10px 0; text-align:center;\">\n<script type=\"text\/javascript\"><!--\r\ngoogle_ad_client = \"ca-pub-2287684400845931\";\r\n\/* valerymorozov *\/\r\ngoogle_ad_slot = \"5606708872\";\r\ngoogle_ad_width = 728;\r\ngoogle_ad_height = 90;\r\n\/\/-->\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\r\n<\/script>\n<\/div>\n<p>The task is to redirect locally ports. <\/p>\n<p>So for example, when you go in browser to http:\/\/a.a.a.a:80, you would like to be always redirected to http:\/\/b.b.b.b:80.<\/p>\n<p>-> http:\/\/a.a.a.a:80<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n------------         --------------\r\n|   Host   |  ---&gt;   | a.a.a.a:80 |\r\n------------         --------------\r\n<\/pre>\n<p>-> http:\/\/a.a.a.a:80<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n------------         --------------\r\n|   Host   |  ---&gt;   | b.b.b.b:80 |\r\n------------         --------------\r\n<\/pre>\n<p>What first comes to one&#8217;s mind? Right, to just add a line to \/etc\/hosts:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n127.0.0.1    localhost\r\na.a.a.a      b.b.b.b\r\n<\/pre>\n<p>That&#8217;s absolutely wrong, because with hosts file you can&#8217;t map one IP address to another.<\/p>\n<p>The right way is to alter iptables OUTPUT table:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">iptables -t nat -A OUTPUT -p tcp -d a.a.a.a --dport 80 -j DNAT --to-destination b.b.b.b:80<\/pre>\n<p>The explanation of this command is <a href=\"http:\/\/unix.stackexchange.com\/a\/85933\" target=\"_blank\">here<\/a>.<\/p>\n<div class=\"2d836d85a73757df15d0de19d7bef594\" data-index=\"1\" style=\"float: none; margin:10px 0 10px 0; text-align:center;\">\n<script type=\"text\/javascript\"><!--\r\ngoogle_ad_client = \"ca-pub-2287684400845931\";\r\n\/* valerymorozov *\/\r\ngoogle_ad_slot = \"5606708872\";\r\ngoogle_ad_width = 728;\r\ngoogle_ad_height = 90;\r\n\/\/-->\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\r\n<\/script>\n<\/div>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>The task is to redirect locally ports. So for example, when you go in browser to http:\/\/a.a.a.a:80, you would like to be always redirected to http:\/\/b.b.b.b:80. -> http:\/\/a.a.a.a:80 &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8211; | Host | &#8212;&gt; | a.a.a.a:80 | &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8211; -> http:\/\/a.a.a.a:80 &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8211; | Host | &#8212;&gt; | b.b.b.b:80 | &hellip; <a class=\"continue-reading-link\" href=\"https:\/\/sandalov.org\/blog\/2129\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2129","post","type-post","status-publish","format-standard","hentry","category-unsorted"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts\/2129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/comments?post=2129"}],"version-history":[{"count":8,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts\/2129\/revisions"}],"predecessor-version":[{"id":2138,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts\/2129\/revisions\/2138"}],"wp:attachment":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/media?parent=2129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/categories?post=2129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/tags?post=2129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}