{"id":122,"date":"2017-01-11T22:01:59","date_gmt":"2017-01-11T15:01:59","guid":{"rendered":"http:\/\/prosindo.com\/blog\/?p=122"},"modified":"2019-03-18T22:03:14","modified_gmt":"2019-03-18T15:03:14","slug":"port-proxy-in-iptables-forwarding-port-to-another-host","status":"publish","type":"post","link":"https:\/\/prosindo.com\/blog\/2017\/01\/11\/port-proxy-in-iptables-forwarding-port-to-another-host\/","title":{"rendered":"Port Proxy in iptables &#8211; Forwarding port to another host"},"content":{"rendered":"<p>Here is the commands, for example you want to forward port 8080 to another host 192.168.100.2:8080<\/p>\n<p>preparation, enable ip forward<br \/>\n<code>sysctl net.ipv4.ip_forward=1<\/code><\/p>\n<p>first we need to masquerade the packet<br \/>\n<code>iptables -t nat -I POSTROUTING -p tcp -j MASQUERADE<\/code><\/p>\n<p>Second, change the destination to another host<br \/>\n<code>iptables -t nat -I PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 192.168.100.2:8080<\/code><\/p>\n<p>Or, listen on specific ip<br \/>\n<code>iptables -t nat -I PREROUTING -p tcp -d 192.168.100.1 --dport 8080 -j DNAT --to-destination 192.168.100.2:8080<\/code><\/p>\n<p>This last is optional, you may need it if your FORWARD chain default REJECT<br \/>\n<code>iptables -I FORWARD -d 192.168.100.2 -p tcp --dport 8080 -j ACCEPT<\/code><\/p>\n<p>Note:<br \/>\n* iptables rules is not persistent, you can make it persistent using iptables-persistent<br \/>\n* you can also use ufw rules, save in the file \/etc\/ufw\/before.rules<\/p>\n<p>Source: https:\/\/askubuntu.com\/questions\/320121\/simple-port-forwarding<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is the commands, for example you want to forward port 8080 to another host 192.168.100.2:8080 preparation, enable ip forward sysctl net.ipv4.ip_forward=1 first we need to masquerade the packet iptables -t nat -I POSTROUTING -p tcp -j MASQUERADE Second, change the destination to another host iptables -t nat -I PREROUTING -p tcp &#8211;dport 8080 -j &hellip; <a href=\"https:\/\/prosindo.com\/blog\/2017\/01\/11\/port-proxy-in-iptables-forwarding-port-to-another-host\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Port Proxy in iptables &#8211; Forwarding port to another host&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[37,38,14,29],"class_list":["post-122","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-forwarding","tag-iptables","tag-linux","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":3,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":190,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions\/190"}],"wp:attachment":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}