{"id":6051,"date":"2022-12-22T08:44:22","date_gmt":"2022-12-22T06:44:22","guid":{"rendered":"https:\/\/skeletor.org.ua\/?p=6051"},"modified":"2022-12-22T08:55:45","modified_gmt":"2022-12-22T06:55:45","slug":"linux-sip-via-nat","status":"publish","type":"post","link":"https:\/\/skeletor.org.ua\/?p=6051","title":{"rendered":"[Linux] Sip via NAT"},"content":{"rendered":"\n<p>\u0420\u043e\u0437\u0433\u043b\u044f\u043d\u0435\u043c\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0456\u044e, \u043a\u043e\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 <strong>asterisk&#8217;a<\/strong> \u0437\u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0437\u0430 <strong>NAT&#8217;\u043e\u043c<\/strong> \u0456 \u0442\u0440\u0435\u0431\u0430 \u0437\u0430\u0440\u0435\u0454\u0441\u0442\u0440\u0443\u0432\u0430\u0442\u0438\u0441\u044f \u0443 <strong>SIP<\/strong> \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430. \u0412 99% \u0432\u0438\u043f\u0430\u0434\u0456\u0432, \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435\u043c\u0430\u0454, \u0430\u043b\u0435 \u0456\u043d\u043a\u043e\u043b\u0438, \u043d\u0456\u0447\u043e\u0433\u043e \u043d\u0435 \u0432\u0438\u0445\u043e\u0434\u0438\u0442\u044c. \u0411\u0456\u043b\u044c\u0448 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0438\u0439 \u0430\u043d\u0430\u043b\u0456\u0437 \u043f\u043e\u043a\u0430\u0437\u0443\u0454, \u0449\u043e \u043f\u0430\u043a\u0435\u0442\u0438 <strong>SIP<\/strong> \u0447\u043e\u043c\u0443\u0441\u044c \u043d\u0435 <strong>NAT&#8217;\u044f\u0442\u044c\u0441\u044f<\/strong>. \u0427\u043e\u043c\u0443? \u0412\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u044c \u0442\u0440\u043e\u0445\u0438 \u043d\u0435\u0437\u0432\u0438\u0447\u043d\u0430, \u044f\u043a\u0449\u043e \u0432\u0438 \u043f\u0440\u0430\u0446\u044e\u0432\u0430\u043b\u0438 \u0437 \u0456\u043d\u0448\u0438\u043c\u0438 <strong>unix<\/strong> <strong>like<\/strong> \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438. \u0414\u0435\u044f\u043a\u0456 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0438 (<strong>FTP<\/strong>, <strong>SIP<\/strong>, &#8230;) \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u044e\u0442\u044c 2 \u0441\u0435\u0441\u0456\u0457 \u0434\u043b\u044f \u0443\u0441\u043f\u0456\u0448\u043d\u043e\u0457 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0456 \u0434\u0430\u043d\u0438\u0445: \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u0430 (\u0432\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044f \u0437\u02bc\u0454\u0434\u043d\u0430\u043d\u043d\u044f) \u0456 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0456 \u0434\u0430\u043d\u0438\u0445. \u0423 \u0456\u043d\u0448\u0438\u0445 \u041e\u0421 (\u0444\u0430\u0439\u0435\u0440\u0432\u043e\u043b\u0430\u0445) \u0432\u0430\u043c \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u0456\u0439\u043d\u043e \u043e\u043f\u0456\u043a\u0443\u0432\u0430\u0442\u0438\u0441\u044f \u0446\u0438\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438, \u044f\u043a\u0456 \u0434\u043e\u0434\u0430\u0442\u043a\u043e\u0432\u0456 \u043f\u043e\u0440\u0442\u0438 \u0432\u0456\u0434\u043a\u0440\u0438\u0442\u0438 \u0430\u0431\u043e \u044f\u043a \u043f\u0435\u0440\u0435\u043d\u0430\u043b\u0430\u0448\u0442\u0443\u0432\u0430\u0442\u0438 \u0437\u02bc\u0454\u0434\u043d\u0430\u043d\u043d\u044f (\u043d\u0430\u043f\u0440\u0438\u043a\u043b\u0430\u0434, \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0437 <strong>active<\/strong> \u043d\u0430 <strong>passive<\/strong> \u0440\u0435\u0436\u0438\u043c \u0432 <strong>FTP<\/strong>). \u0412 <strong>Linux<\/strong> \u0434\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043c\u0435\u0445\u0430\u043d\u0456\u0437\u043c <strong>conntrack<\/strong> (<strong>connection<\/strong> <strong>tracker<\/strong>), \u044f\u043a\u0438\u0439 &#8220;\u0437\u0430\u0437\u0438\u0440\u0430\u0454&#8221; \u0432\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443 \u0437\u02bc\u0454\u0434\u043d\u0430\u043d\u043d\u044f \u0456 \u0434\u043e\u0437\u0432\u043e\u043b\u044f\u0454 \u0441\u0442\u0432\u043e\u0440\u0438\u0442\u0438 \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u043d\u0435 \u0434\u0438\u043d\u0430\u043c\u0456\u0447\u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e (\u043d\u0430\u0441\u043f\u0440\u0430\u0432\u0434\u0456 \u0446\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0442\u0440\u0435\u0431\u0430 \u0441\u0442\u0432\u043e\u0440\u0438\u0442\u0438 \u043e\u043a\u0440\u0435\u043c\u043e, \u0430\u043b\u0435 \u0442\u0430\u043c \u043c\u0438 \u043d\u0435 \u0432\u043a\u0430\u0437\u0443\u0454\u043c\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0456 \u043f\u043e\u0440\u0442\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043a\u0430\u0437\u0443\u0454\u043c\u043e, \u0449\u043e \u0446\u0435 \u0432\u0456\u0434\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u0434\u043e, \u043d\u0430\u043f\u0440\u0438\u043a\u043b\u0430\u0434, <strong>SIP<\/strong> \u0456 \u043f\u0430\u043a\u0435\u0442\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u0431\u0443\u0434\u0443\u0442\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u0438). \u0427\u0438 \u0446\u0435 \u0434\u043e\u0431\u0440\u0435? \u0406 \u0442\u0430\u043a \u0456 \u043d\u0456. \u0427\u043e\u043c\u0443 \u0434\u043e\u0431\u0440\u0435 &#8211; \u0437\u0440\u043e\u0437\u0443\u043c\u0456\u043b\u043e. \u0427\u043e\u043c\u0443 \u043d\u0456? \u0422\u043e\u043c\u0443 \u0449\u043e, \u0456\u043d\u043a\u043e\u043b\u0438 \u0432\u0438\u043d\u0438\u043a\u0430\u044e\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0438, \u043f\u0440\u043e \u044f\u043a\u0456 \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u043f\u043e\u0447\u0430\u0442\u043a\u0443 \u0441\u0442\u0430\u0442\u0442\u0456.<\/p>\n\n\n<p><!--more--><\/p>\n\n\n<p>\u041e\u0442\u0436\u0435, \u0443 \u043d\u0430\u0441 \u043d\u0430\u043b\u0430\u0448\u0442\u043e\u0432\u0430\u043d\u0438\u0439 conntrack  <strong>helper SIP<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">net.netfilter.nf_conntrack_helper=1<\/pre>\n\n\n\n<p>\u0456 \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u043d\u0456 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0443 <strong>iptables<\/strong>:<\/p>\n\n\n\n<p><code>iptables -t raw -A OUTPUT -p udp -m udp -m conntrack --sport 5060 --ctstate NEW,RELATED,ESTABLISHED -m state --state NEW,RELATED,ESTABLISHED -m helper --helper sip -j CT<br>iptables -t raw -A OUTPUT -p udp -m udp -m conntrack --dport 5060 --ctstate NEW,RELATED,ESTABLISHED -m state --state NEW,RELATED,ESTABLISHED -m helper --helper sip -j CT<\/code><\/p>\n\n\n<p>\u0410\u043b\u0435 \u0432\u0441\u0435 \u043e\u0434\u043d\u043e \u043d\u0456\u0447\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0430\u0446\u044e\u0454. \u041f\u043e\u0434\u0438\u0432\u0438\u043b\u0438\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <strong>conntrack -L<\/strong> \u0456 \u0442\u0430\u043c \u0442\u0435\u0436 \u0441\u0435\u0441\u0456\u0457 \u0454. \u0412 \u0447\u043e\u043c\u0443 \u0436 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430? \u041f\u043e\u043a\u0438 \u043d\u0435\u043c\u0430\u0454 \u0443 \u043c\u0435\u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0457 \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u0456, \u0456 \u044f \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u044e\u0441\u044f \u0442\u0430\u043a\u0438\u043c workaround&#8217;\u043e\u043c, \u044f\u043a \u0432\u0438\u0434\u0430\u043b\u0438\u0442\u0438 \u0432\u0441\u0456 \u0441\u0435\u0441\u0456\u0457 <strong>asterisk&#8217;a<\/strong>:<\/p>\n<p><code># conntrack -D -s 10.0.1.11<br \/>\n<\/code><\/p>\n<p>\u0406 \u043f\u0456\u0441\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u043f\u043e\u0447\u0438\u043d\u0430\u0454 \u0432\u0441\u0435 \u043f\u0440\u0430\u0446\u044e\u0432\u0430\u0442\u0438. \u0404 \u043f\u0440\u0438\u043f\u0443\u0449\u0435\u043d\u043d\u044f, \u0449\u043e \u0442\u0430\u043a\u0430 \u043f\u043e\u0432\u0435\u0434\u0456\u043d\u043a\u0430 \u0437\u02bc\u044f\u0432\u043b\u044f\u044e\u0442\u044c\u0441\u044f \u043f\u0456\u0441\u043b\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0445\u043e\u0441\u0442\u0430 \u0437 <strong>asterisk&#8217;\u043e\u043c<\/strong> \u0456 \u044f\u043a \u0446\u0435 \u0432\u0456\u0434\u0441\u043b\u0456\u0434\u043a\u043e\u0432\u0443\u0432\u0430\u0442\u0438 \u043d\u0430 <strong>conntrack<\/strong>, \u0449\u043e\u0431 \u0432\u0456\u043d \u0432\u0438\u0434\u0430\u043b\u044f\u0432 \u0442\u0430\u043a\u0456 \u0441\u0435\u0441\u0456\u0457 &#8211; \u043f\u043e\u043a\u0438 \u043d\u0435 \u0437\u043d\u0430\u044e. \u0425\u0442\u043e\u0441\u0442 \u043c\u043e\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u0438, \u0449\u043e \u0442\u0440\u0435\u0431\u0430 \u0432\u0438\u0441\u0442\u0430\u0432\u0438\u0442\u0438 timeout&#8217;\u0438 \u043d\u0430 <strong>conntrack<\/strong>, \u0430\u043b\u0435 \u0432\u043e\u043d\u0438 \u0454 \u0456 \u043d\u0435 \u0434\u0456\u044e\u0442\u044c:<\/p>\n<p><code>net.netfilter.nf_conntrack_udp_timeout=30<\/code><\/p>","protected":false},"excerpt":{"rendered":"<p>\u0420\u043e\u0437\u0433\u043b\u044f\u043d\u0435\u043c\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0456\u044e, \u043a\u043e\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 asterisk&#8217;a \u0437\u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0437\u0430 NAT&#8217;\u043e\u043c \u0456 \u0442\u0440\u0435\u0431\u0430 \u0437\u0430\u0440\u0435\u0454\u0441\u0442\u0440\u0443\u0432\u0430\u0442\u0438\u0441\u044f \u0443 SIP \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430. \u0412 99% \u0432\u0438\u043f\u0430\u0434\u0456\u0432, \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435\u043c\u0430\u0454, \u0430\u043b\u0435 \u0456\u043d\u043a\u043e\u043b\u0438, \u043d\u0456\u0447\u043e\u0433\u043e \u043d\u0435 \u0432\u0438\u0445\u043e\u0434\u0438\u0442\u044c. \u0411\u0456\u043b\u044c\u0448 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0438\u0439 \u0430\u043d\u0430\u043b\u0456\u0437 \u043f\u043e\u043a\u0430\u0437\u0443\u0454, \u0449\u043e \u043f\u0430\u043a\u0435\u0442\u0438 SIP \u0447\u043e\u043c\u0443\u0441\u044c \u043d\u0435 NAT&#8217;\u044f\u0442\u044c\u0441\u044f. \u0427\u043e\u043c\u0443? \u0412\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u044c \u0442\u0440\u043e\u0445\u0438 \u043d\u0435\u0437\u0432\u0438\u0447\u043d\u0430, \u044f\u043a\u0449\u043e \u0432\u0438 \u043f\u0440\u0430\u0446\u044e\u0432\u0430\u043b\u0438 \u0437 \u0456\u043d\u0448\u0438\u043c\u0438 unix like \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438. \u0414\u0435\u044f\u043a\u0456 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0438 (FTP, SIP, &#8230;) \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u044e\u0442\u044c 2 \u0441\u0435\u0441\u0456\u0457 \u0434\u043b\u044f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,7],"tags":[],"class_list":["post-6051","post","type-post","status-publish","format-standard","hentry","category-linux","category-telephony"],"_links":{"self":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/6051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6051"}],"version-history":[{"count":3,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/6051\/revisions"}],"predecessor-version":[{"id":6055,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/6051\/revisions\/6055"}],"wp:attachment":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}