{"id":40,"date":"2012-07-04T13:49:30","date_gmt":"2012-07-04T07:49:30","guid":{"rendered":"http:\/\/alexeyka.zantsev.com\/?p=40"},"modified":"2013-07-17T16:22:53","modified_gmt":"2013-07-17T10:22:53","slug":"iptables-%d0%b2-ubuntu","status":"publish","type":"post","link":"https:\/\/alexeyka.zantsev.com\/?p=40","title":{"rendered":"iptables \u0432 Ubuntu"},"content":{"rendered":"<div>\n<p>\u042f \u043f\u0440\u0438\u0432\u044b\u043a \u043a slackware-way \u043f\u0440\u0438 \u201c\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438\u201d \u043f\u0440\u0430\u0432\u0438\u043b iptables &#8211; \u0441\u043a\u0440\u0438\u043f\u0442 rc.firewall, \u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u0432 \/etc\/rc.d\/ , \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432 \u0441\u0435\u0431\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043f\u0440\u0430\u0432\u0438\u043b iptables \u0438 \u0443\u043c\u0435\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f start\/stop\/restart.<\/p>\n<p>\u041d\u043e \u0432 GNU\/Linux, \u043a\u0430\u043a \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0439 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <strong>iptables<\/strong> \u0432 <strong>Ubuntu<\/strong>. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043f\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u043c <a href=\"https:\/\/help.ubuntu.com\/community\/IptablesHowTo#Configuration%20on%20startup\" target=\"_blank\">https:\/\/help.ubuntu.com\/community\/IptablesHowTo#Configuration%20on%20startup<\/a> .<\/p>\n<p><strong>\u0412\u043d\u0418\u041c\u0410\u043d\u0438\u0435!<\/strong> \u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0435 \u0444\u0430\u0439\u0440\u0432\u043e\u043b \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435. \u0415\u0441\u043b\u0438 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0439, \u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0438 INPUT, \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0439\u0442\u0435 (sudo iptables -P INPUT ACCEPT), \u0430 \u0443\u0436 \u043f\u043e\u0442\u043e\u043c, \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u044d\u0442\u0430\u043f\u0435, \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0439\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0430\u0432\u043a\u0443 \u043a\u043e\u043d\u0444\u0438\u0433\u0430, \u0438\u043c\u0435\u044f \u0443\u0436\u0435 \u044f\u0432\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430.<\/p>\n<p>1 \u0448\u0430\u0433.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0451\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0430\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e:<br \/>\n<em>sudo iptables -P INPUT DROP<\/em><br \/>\n<em>sudo iptables -P FORWARD DROP<\/em> # \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d IP-forwarding, \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u043e, \u0434\u0443\u043c\u0430\u044e, \u043b\u0438\u0448\u043d\u0438\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<br \/>\n# <em>sudo iptables -P OUTPUT DROP<\/em> # \u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u043b, \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0440\u0435\u0448\u0430\u0439\u0442\u0435 \u0441\u0430\u043c\u0438. \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 OUTPUT \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u043e:<br \/>\n<em>sudo iptables -A OUTPUT -m state \u2014state ESTABLISHED,RELATED -j ACCEPT<\/em><\/p>\n<p>2 \u0448\u0430\u0433.<\/p>\n<p>\u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0442\u0440\u0430\u0444\u0438\u043a \u043d\u0430 loopback-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435:<\/p>\n<p><em>sudo iptables -A INPUT -i lo -j ACCEPT<\/em><\/p>\n<p>3 \u0448\u0430\u0433.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u0430 \u043d\u0430\u0448\u0443 \u043c\u0430\u0448\u0438\u043d\u0443:<br \/>\n<em>sudo iptables -A INPUT -p tcp \u2014dport 22 -j ACCEPT<\/em><br \/>\n\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\/\u043e\u043f\u0446\u0438\u0438.<\/p>\n<p>4 \u0448\u0430\u0433.<\/p>\n<p>\u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u043e\u043c ESTABLISHED \u0438 RELATED:<br \/>\n<em>sudo iptables -A INPUT -m state \u2014state ESTABLISHED,RELATED -j ACCEPT<\/em><\/p>\n<p>5 \u0448\u0430\u0433.<\/p>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432 \u0444\u0430\u0439\u043b \/etc\/iptables.rules:<\/p>\n<p><em>sudo bash -c \u201ciptables-save &gt; \/etc\/iptables.rules\u201d<\/em><\/p>\n<p>6 \u0448\u0430\u0433.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \/etc\/network\/if-pre-up.d\/iptablesload \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<br \/>\n<em>#!\/bin\/sh<\/em><br \/>\n<em>iptables-restore &lt; \/etc\/iptables.rules<\/em><br \/>\n<em>exit 0<\/em><\/p>\n<p>7 \u0448\u0430\u0433.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \/etc\/network\/if-post-down.d\/iptablessave \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<br \/>\n<em>#!\/bin\/sh<\/em><br \/>\n<em>iptables-save -c &gt; \/etc\/iptables.rules<\/em><br \/>\n<em>if [ -f \/etc\/iptables.downrules ]; then<\/em><br \/>\n<em>\u00a0\u00a0 iptables-restore &lt; \/etc\/iptables.downrules<\/em><br \/>\n<em>fi<\/em><br \/>\n<em>exit 0<\/em><\/p>\n<p>8 \u0448\u0430\u0433.<\/p>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c\u0438:<br \/>\n<em>sudo chmod +x \/etc\/network\/if-pre-up.d\/iptablesload<\/em><br \/>\n<em>sudo chmod +x \/etc\/network\/if-post-down.d\/iptablessave<\/em><\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 <em>\/etc\/network\/if-pre-up.d\/iptablesload<\/em> \u0434\u043b\u044f \u0432\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0441\u0438\u043b\u0443.<em><br \/>\n<\/em><\/p>\n<p><strong>\u041e \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435.<\/strong><\/p>\n<p>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u0430\u0448 \u0444\u0430\u0439\u043b \/etc\/iptables.rules . \u0412\u0430\u043c \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u201c\u0437\u0430\u0445\u043b\u0430\u043c\u043b\u0451\u043d\u201d (\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043d\u0435 \u0432\u0441\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435)\u00a0?<\/p>\n<blockquote><p># Generated by iptables-save v1.4.4 on Mon May 23\u00a015:20:51\u00a02011<br \/>\n*filter<br \/>\n:INPUT DROP [172:18570]<br \/>\n:FORWARD DROP [0:0]<br \/>\n:OUTPUT ACCEPT [681:120764]<br \/>\n[30:1727] -A INPUT -i lo -j ACCEPT<br \/>\n[0:0] -A INPUT -p tcp -m tcp \u2014dport 22 -j ACCEPT<br \/>\n[0:0] -A INPUT -p tcp -m tcp -m multiport \u2014dports 135,139,445 -j ACCEPT<br \/>\n[176:17992] -A INPUT -p udp -m udp -m multiport \u2014dports 137,138 -j ACCEPT<br \/>\n#<br \/>\n-A INPUT -p icmp -m icmp \u2014icmp-type 8 -j ACCEPT<br \/>\n#<br \/>\n[556:391583] -A INPUT -m state \u2014state RELATED,ESTABLISHED -j ACCEPT<br \/>\nCOMMIT<br \/>\n# Completed on Mon May 23\u00a015:20:51\u00a02011<\/p><\/blockquote>\n<p>\u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043f\u0440\u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u0440\u0430\u0432\u043a\u0435 \u0444\u0430\u0439\u043b\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u0441\u0442\u0440\u043e\u043a \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0431\u044b\u043b\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e \u0441\u043b\u043e\u0432\u043e\u043c \u201cCOMMIT\u201d, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u0438 \u201c\u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435\u201d \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0440\u0430\u0432\u0438\u043b iptables, \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043d\u0435 \u0432\u0441\u0442\u0443\u043f\u044f\u0442 \u0432 \u0441\u0438\u043b\u0443.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u0435\u043d \u043c\u043d\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u042f \u043f\u0440\u0438\u0432\u044b\u043a \u043a slackware-way \u043f\u0440\u0438 \u201c\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438\u201d \u043f\u0440\u0430\u0432\u0438\u043b iptables &#8211; \u0441\u043a\u0440\u0438\u043f\u0442 rc.firewall, \u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u0432 \/etc\/rc.d\/ , \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432 \u0441\u0435\u0431\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043f\u0440\u0430\u0432\u0438\u043b iptables \u0438 \u0443\u043c\u0435\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f start\/stop\/restart. \u041d\u043e \u0432 GNU\/Linux, \u043a\u0430\u043a \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0439 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 iptables \u0432 Ubuntu. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043f\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u043c https:\/\/help.ubuntu.com\/community\/IptablesHowTo#Configuration%20on%20startup . \u0412\u043d\u0418\u041c\u0410\u043d\u0438\u0435! [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20,9,19],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-iptables","tag-linux","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":4,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}