{"id":1512,"date":"2012-09-27T15:43:58","date_gmt":"2012-09-27T07:43:58","guid":{"rendered":"http:\/\/rmohan.com\/?p=1512"},"modified":"2012-09-27T15:43:58","modified_gmt":"2012-09-27T07:43:58","slug":"iptables-rewirte-for-8080-and-8443","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1512","title":{"rendered":"Iptables rewirte for 8080 and 8443"},"content":{"rendered":"<p>Another way of achieving the same thing is to add an iptable redirection rule.<\/p>\n<p>We have done it this way, because we didn&#8217;t want to add the xinit package to our standard configuration.<\/p>\n<p>These instructions were created on a Debian Lenny system.<\/p>\n<p>Create a new &#8220;if-up&#8221; script:<br \/>sudo vim \/etc\/network\/if-up.d\/jira-redirect<\/p>\n<p>Make this its content:<\/p>\n<p>#!\/bin\/bash<br \/>for i in $(sudo ifconfig\u00a0 | grep &#8216;inet addr:&#8217;| grep -v &#8216;127.0.0.1&#8217; | cut -d: -f2 | awk &#8216;{ print $1}&#8217;); do<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sudo iptables -t nat -I PREROUTING 1 -d $i -p tcp &#8211;dport 80 -j DNAT &#8211;to $i:8080<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sudo iptables -t nat -I PREROUTING 1 -d $i -p tcp &#8211;dport 443 -j DNAT &#8211;to $i:8443<br \/>done<\/p>\n<p>This script will take all the IPs the server is using as shown by ifconfig, and will add the redirect rules for them.<\/p>\n<p>Make the script executable:<br \/>sudo chmod +x \/etc\/network\/if-up.d\/jira-redirect<\/p>\n<p>Create a new &#8220;if-down&#8221; script:<br \/>sudo vim \/etc\/network\/if-down.d\/jira-redirect-clearer<\/p>\n<p>Make this its content:<\/p>\n<p>#!\/bin\/bash<br \/>sudo iptables -F -t nat<\/p>\n<p>This script will clear all the NAT rules by using the flush (-F) directive, when the networking is restarted.<\/p>\n<p>Adding this &#8220;if-down&#8221; script better handles cases where you changed a networking setting and the old ones are still there until a reboot. however as this does clear ALL of the NAT settings, make sure this doesn&#8217;t affect other things on your setup.<\/p>\n<p>Make the script executable:<br \/>sudo chmod +x \/etc\/network\/if-down.d\/jira-redirect-clearer<\/p>\n<p>Restart the networking service for the changes to take affect:<br \/>sudo \/etc\/init.d\/networking restart<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Another way of achieving the same thing is to add an iptable redirection rule.<\/p>\n<p>We have done it this way, because we didn&#8217;t want to add the xinit package to our standard configuration.<\/p>\n<p>These instructions were created on a Debian Lenny system.<\/p>\n<p>Create a new &#8220;if-up&#8221; script:sudo vim \/etc\/network\/if-up.d\/jira-redirect<\/p>\n<p>Make this its content:<\/p>\n<p>#!\/bin\/bashfor i [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1512"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1512"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1512\/revisions"}],"predecessor-version":[{"id":1513,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1512\/revisions\/1513"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}