{"id":1454,"date":"2018-01-02T15:08:40","date_gmt":"2018-01-02T20:08:40","guid":{"rendered":"http:\/\/www.xavignu.com\/?p=1454"},"modified":"2018-01-04T15:08:25","modified_gmt":"2018-01-04T20:08:25","slug":"script-to-place-in-dmz","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=1454","title":{"rendered":"Script to place in DMZ"},"content":{"rendered":"<p>So I had to place a small server in my home <a href=\"https:\/\/en.wikipedia.org\/wiki\/DMZ_%28computing%29\" target=\"_blank\">DMZ<\/a> leaving it opened to the whole world with the corresponding risks this has. Wondering how to allow access from my home <a href=\"https:\/\/en.wikipedia.org\/wiki\/Local_area_network\" target=\"_blank\">LAN<\/a> I came up with the following <a href=\"http:\/\/netfilter.org\/\" target=\"_blank\">iptables<\/a> script.<\/p>\n<p>[bash]<br \/>\n#!\/bin\/bash<\/p>\n<p>IPTABLES=\/sbin\/iptables<br \/>\nINT=eth0<\/p>\n<p>startiptables() {<br \/>\n\tif [ ${UID} -eq 0 ]; then<br \/>\n\t\t${IPTABLES} -A INPUT -i ${INT} -s 192.168.1.0\/24 -j ACCEPT<br \/>\n\t\t${IPTABLES} -A INPUT -i ${INT} -m state &#8211;state RELATED,ESTABLISHED -j ACCEPT<br \/>\n\t\t${IPTABLES} -A INPUT -i ${INT} -j REJECT<br \/>\n\telse<br \/>\n                echo &#8220;Your UID is: ${UID}. Execute as superuser please&#8221;<br \/>\n        fi<br \/>\n}<\/p>\n<p>stopiptables() {<br \/>\n\tif [ ${UID} -eq 0 ]; then<br \/>\n\t\t${IPTABLES} -F<br \/>\n\t\t${IPTABLES} -L<br \/>\n\telse<br \/>\n                echo &#8220;Your UID is: ${UID}. Execute as superuser please&#8221;<br \/>\n        fi<br \/>\n}<\/p>\n<p>statusiptables() {<br \/>\n\tif [ ${UID} -eq 0 ]; then<br \/>\n\t\t${IPTABLES} -L<br \/>\n\telse<br \/>\n\t\techo &#8220;Your UID is: ${UID}. Execute as superuser please&#8221;<br \/>\n\tfi<br \/>\n}<\/p>\n<p>case &#8220;$1&#8221; in<br \/>\n\tstart)\tstartiptables ;;<br \/>\n\tstop)\tstopiptables ;;<br \/>\n\tstatus) statusiptables ;;<br \/>\n\t*) echo &#8220;usage: $0 start|stop|status&#8221; >&#038;2<br \/>\n\t\texit 1<br \/>\n\t\t;;<br \/>\nesac<br \/>\n[\/bash]<\/p>\n<p>Pretty simple as you can see. It will allow all connections from inside home LAN and block all unrelated traffic coming from the public, except the related and established ones. Substitute the classic <a href=\"https:\/\/en.wikipedia.org\/wiki\/Classful_network\" target=\"_blank\">class C<\/a> on script for your corresponding home\/work network.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I had to place a small server in my home DMZ leaving it opened to the whole world with the corresponding risks this has. Wondering how to allow access from my home LAN I came up with the following iptables script. [bash] #!\/bin\/bash IPTABLES=\/sbin\/iptables INT=eth0 startiptables() { if [ ${UID} -eq 0 ]; then [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[56,4,6,70],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-ns","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1454"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1454"}],"version-history":[{"count":3,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1454\/revisions"}],"predecessor-version":[{"id":1461,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1454\/revisions\/1461"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}