{"id":492,"date":"2012-11-30T19:55:31","date_gmt":"2012-11-30T17:55:31","guid":{"rendered":"http:\/\/www.netexpertise.eu\/en\/?p=492"},"modified":"2021-05-05T22:47:47","modified_gmt":"2021-05-05T20:47:47","slug":"iptables-traffic-redirection","status":"publish","type":"post","link":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html","title":{"rendered":"IPTables Traffic Redirection on Linux"},"content":{"rendered":"\n<p>Whether you need to redirect telnet or ssh connections through a server because you don&#8217;t have direct access to your final destination or you&#8217;re planning a web server migration, traffic forwarding comes in handy in many situations.<br>This is easily achieved on Linux distributions that come with IPtables. Yes, <a href=\"\/en\/tag\/iptables\">iptables<\/a> isn&#8217;t just for ACL rules, but also provides nat feature.<br>\u00a0<br>First off, allow IP forwarding. This authorise packets to pass through the server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">linux_server$ echo 1 >\/proc\/sys\/net\/ipv4\/ip_forward<\/code><\/pre>\n\n\n\n<p>\u00a0<br>The next step is to tell iptables to NAT the traffic to the destination server (http, port 80 in this case):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">linux_server$ iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination dst_srv_IP<\/code><\/pre>\n\n\n\n<p>\u00a0<br>In this final step, this is where iptables handles paquets sent back by the destination machine. Traffic then returns to the original client.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">linux_server$ iptables -t nat -A POSTROUTING -d dst_srv_IP -p tcp -m tcp --dport 80 -j MASQUERADE<\/code><\/pre>\n\n\n\n<p><br>That way, you can easily forward traffic to a new web server. Clients experience no downtime while DNS entries get updated and spread across clients.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whether you need to redirect telnet or ssh connections through a server because you don&#8217;t have direct access to your final destination or you&#8217;re planning a web server migration, traffic forwarding comes in handy in many situations.This is easily achieved on Linux distributions that come with IPtables. Yes, iptables isn&#8217;t just for ACL rules, but [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[11],"tags":[293,292,386,99],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netexpertise - IPTables Traffic Redirection on Linux<\/title>\n<meta name=\"description\" content=\"Forward network traffic on Linux to another host with IPtables\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netexpertise - IPTables Traffic Redirection on Linux\" \/>\n<meta property=\"og:description\" content=\"Forward network traffic on Linux to another host with IPtables\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html\" \/>\n<meta property=\"og:site_name\" content=\"Netexpertise\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-30T17:55:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-05T20:47:47+00:00\" \/>\n<meta name=\"author\" content=\"dave\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@netexpertise\" \/>\n<meta name=\"twitter:site\" content=\"@netexpertise\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html\",\"url\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html\",\"name\":\"Netexpertise - IPTables Traffic Redirection on Linux\",\"isPartOf\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\"},\"datePublished\":\"2012-11-30T17:55:31+00:00\",\"dateModified\":\"2021-05-05T20:47:47+00:00\",\"author\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\"},\"description\":\"Forward network traffic on Linux to another host with IPtables\",\"breadcrumb\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.netexpertise.eu\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IPTables Traffic Redirection on Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\",\"url\":\"http:\/\/www.netexpertise.eu\/en\/\",\"name\":\"Netexpertise\",\"description\":\"Systems \/ Networks \/ DevOps\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\",\"name\":\"dave\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"caption\":\"dave\"},\"sameAs\":[\"http:\/\/www.netexpertise.eu\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netexpertise - IPTables Traffic Redirection on Linux","description":"Forward network traffic on Linux to another host with IPtables","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html","og_locale":"en_US","og_type":"article","og_title":"Netexpertise - IPTables Traffic Redirection on Linux","og_description":"Forward network traffic on Linux to another host with IPtables","og_url":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html","og_site_name":"Netexpertise","article_published_time":"2012-11-30T17:55:31+00:00","article_modified_time":"2021-05-05T20:47:47+00:00","author":"dave","twitter_card":"summary_large_image","twitter_creator":"@netexpertise","twitter_site":"@netexpertise","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html","url":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html","name":"Netexpertise - IPTables Traffic Redirection on Linux","isPartOf":{"@id":"http:\/\/www.netexpertise.eu\/en\/#website"},"datePublished":"2012-11-30T17:55:31+00:00","dateModified":"2021-05-05T20:47:47+00:00","author":{"@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa"},"description":"Forward network traffic on Linux to another host with IPtables","breadcrumb":{"@id":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/iptables-traffic-redirection.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.netexpertise.eu\/en"},{"@type":"ListItem","position":2,"name":"IPTables Traffic Redirection on Linux"}]},{"@type":"WebSite","@id":"http:\/\/www.netexpertise.eu\/en\/#website","url":"http:\/\/www.netexpertise.eu\/en\/","name":"Netexpertise","description":"Systems \/ Networks \/ DevOps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa","name":"dave","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","caption":"dave"},"sameAs":["http:\/\/www.netexpertise.eu"]}]}},"_links":{"self":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/492"}],"collection":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/comments?post=492"}],"version-history":[{"count":0,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/492\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/media?parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/categories?post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/tags?post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}