<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Mikrotik.moscow [тема: Динамический IP пробрасывается в BIND9.]</title>
		<link>http://mikrotik.moscow</link>
		<description>Новое в теме Динамический IP пробрасывается в BIND9. форума RouterOS на сайте Mikrotik.moscow [mikrotik.moscow]</description>
		<language>ru</language>
		<docs>http://backend.userland.com/rss2</docs>
		<pubDate>Mon, 17 Aug 2026 14:23:14 -0400</pubDate>
		<item>
			<title>Динамический IP пробрасывается в BIND9.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/62834-dinamicheskiy-ip-probrasyvaetsya-v-bind9./message241247">Динамический IP пробрасывается в BIND9.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			UNIX-системные админы любят роутеры MikrotiK, но часто провайдер не выдаёт статический IP. Сегодня я исправил эту проблему, но бесплатный DynDNS больше не работает. ;( Как и многие системные администраторы, у меня есть доступ к веб-серверу на базе Linux. Тогда я написал скрипт для MikrotiK на основе "HTTP GET" для отправки IP-адреса. Он отправляет мой внешний IP на веб-сервер, а PHP5 часть веб-сервера генерирует файл зоны, совместимый с BIND9. После этого перезагружается конфигурация BIND9 для загрузки новой зоны и отправляется уведомление на вторичный DNS. И мне больше не нужен никакой внешний сервис DDNS.<br /><br />MikrotiK скрипт<br />```<br />:local sendhost "dns.mywebserver.ru";<br /># Zone<br />:local host "mydomain.net";<br /># Access password<br />:local password "passwordblablabla";<br /># Mikrotik external IFace<br />:local iface "beeline-l2tp";<br /># Location of PHP script in web-server home dir<br />:local script "/update_dns.php";<br /><br /># get current IP address from DNS system<br />:local currentdnsaddress [ :resolve $host ];<br /># get Mikrotik external address<br />:local iptemp [ /ip address get [find interface=$iface] address ];<br /># cut IP without mask<br />:local str [:pick $iptemp 0 [:find $iptemp "/"]];<br /><br /># if DNS address not equal our external<br />:if ($str != $currentdnsaddress) do={<br /> &nbsp; &nbsp;:log info "Update DynamicIP needed, Sending UPDATE...!"<br /># make request parameters<br /> &nbsp; &nbsp;:local str2 "$script\?hostip=$str&password=$password&host=$host";<br />:put $str2<br /># execute GET http request with parameters<br /> &nbsp; &nbsp;/tool fetch address=$sendhost host=$sendhost src-path=$str2 mode=http keep-result=no;<br />} else={ :log info "DynamicIP: dont need changes"; }<br />```<br /><br />PHP5 скрипт update_dns.php<br />```php<br />&lt;?<br />//<br />// Author: Andrey Bykanov (adm@shodtech.net)<br />//<br />// BIND9 Dynamic IP update script<br />////////////////////////////////////////////////////////////<WBR/>&shy;////////////////////////////////////////////<br /><br />$password="passwordblablabla";<br />$host="mydomain.net";<br /><br />////////////////////////////////////////////////////////////<WBR/>&shy;////////////////////////////////////////////<br />function is_ipv4($string)<br />{<br /> &nbsp; &nbsp;// The regular expression checks for any number between 0 and 255 beginning with a dot (repeated 3 times)<br /> &nbsp; &nbsp;// followed by another number between 0 and 255 at the end. The equivalent to an IPv4 address.<br /><br /> &nbsp; &nbsp;return (bool) preg_match('/^(?<img  src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="http://mikrotik.moscow/upload/main/smiles/2/bx_smile_sad.png" border="0" data-code=":(" data-definition="UHD" alt=":(" style="width:20px;height:20px;" title="Печально" class="lazyload bx-smile" />?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])'.'\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|[0-9])$/', $string);<br />}<br />////////////////////////////////////////////////////////////<WBR/>&shy;////////////////////////////////////////////<br /><br />if(isset($_GET["password"]) & isset($_GET["hostip"]) & isset($_GET["host"])) // check for all nesesery parameters is exist<br />{<br /> &nbsp; &nbsp;if($_GET["password"]!=$password){echo "Неверный пароль: ".$_GET["password"]; die();} // Check password<br /> &nbsp; &nbsp;if($_GET["host"]!=$host)        {echo "Неверное имя хоста: ".$_GET["host"];         die();} // Check hostname<br /> &nbsp; &nbsp;if(!(is_ipv4($_GET["hostip"]) & ($_SERVER["HTTP_X_REAL_IP"]==$_GET["hostip"]))){echo " Неверный IP-адрес : ".$_GET["hostip"]; die();} // Check IP address<br /><br />$zone_time=(integer)(((date('H')*60)+date('i'))/15); // Calculate Zone time, one tick is allmost 15 minutes<br />$zone_date=date('Ymd').$zone_time; // Calculate complette zone serial eg, YearMonthDayTime<br /><br />$fp = fopen('shodtech.net_zone_data.txt', 'w'); // zone file name<br />// Writing BIND9 Zone content<br />fwrite($fp, "\$ORIGIN mydomain.net. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\r\n");<br />fwrite($fp, "\$TTL 600 &nbsp; &nbsp; &nbsp; ; 10 minutes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\r\n");<br />fwrite($fp, "@ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IN SOA &nbsp;ns.mydomain.net. adm.mydomain.net. ( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;".$zone_date." ; serial &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;600 &nbsp; &nbsp; &nbsp; ; refresh (10 minutes) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;600 &nbsp; &nbsp; &nbsp; ; retry (10 minutes) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;86400 &nbsp; &nbsp; ; expire (1 day) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;600 &nbsp; &nbsp; &nbsp; ; minimum (10 minutes) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp; &nbsp;ns1.mywebserver.ru. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp; &nbsp;ns2.mywebserver.ru. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \r\n");<br />fwrite($fp, " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; &nbsp; ".$_GET["hostip"]."                         \r\n"); // Put Mikrotik external IP address<br />fwrite($fp, "ftp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; &nbsp; ".$_GET["hostip"]."                         \r\n"); // Put Mikrotik external IP address<br />fwrite($fp, "www &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; ".$_GET["hostip"]."                         \r\n"); // Put Mikrotik external IP address<br /><br />fclose($fp); // Close file<br /><br />exec('/usr/sbin/rndc reload'); // Reloading BIND9 config (Web-server must have permission for write to /etc/bind/rndc.key)<br /><br /><br />} else echo "Неверные параметры";<br /><br />?&gt;<br />```<br /><br />Часть конфигурации BIND9 "mydomain.net"<br />```<br />{<br />type master;<br />file "/var/www/mydomain.net_zone_data.txt"; // Full path to zone file generated by PHP script<br />allow-update { none;};<br />allow-query {any; } ;<br />allow-transfer { 62.12.13.12; } ; // IP to transfer zone (Secondary DNS)<br />notify yes;<br />};<br />```<br /><br />`.htaccess`<br />```<br />Options All -Indexes<br />Deny from All<br /><br />&lt;Files "update_dns.php"&gt;<br /> &nbsp; &nbsp;Allow from All<br />&lt;/Files&gt;<br />``` <br />
			<i>01.12.2013 14:54:00, shodan.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/62834-dinamicheskiy-ip-probrasyvaetsya-v-bind9./message241247</link>
			<guid>http://mikrotik.moscow/forum/forum57/62834-dinamicheskiy-ip-probrasyvaetsya-v-bind9./message241247</guid>
			<pubDate>Sun, 01 Dec 2013 14:54:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
	</channel>
</rss>
