动态添加zone addzone

本文介绍如何使用BIND 9.7.2-P2的实验性功能动态添加和删除DNS区域,无需编辑配置文件或重启服务器。管理员可通过rndc命令在运行时进行操作,使更改立即生效并持久化。

http://jpmens.net/2010/10/04/dynamically-add-zones-to-bind-with-rndc-addzone/


The BIND name server (version 9.7.2-P2) has an experimental feature allowing administrators to dynamically add and remove zones at run-time, without having to edit named.conf and reload/reconfigure the name server. Beware though: the documentation explicitly states that this feature is currently experimental. In order for this to work, the server’s options or view must contain the directive

    allow-new-zones yes;
    

You use the rndc command to add or delete a zone to a view. For example, to add a master zone called example.aa from the file master/example.aa (relative to the name server’s directory) to a view called myview, I issue the following command.

    rndc addzone example.aa in myview '{type master; file "master/example.aa";};'
    

The zone is added to the running name server, and it is added to a configuration file. The filename is a hash of the view name with extension .nzf. (Which might stand for new zone file?) The file’s content is

    zone example.aa {type master; file "master/example.aa";};
    

Upon restarting named, the server automatically attempts to load this file. It appears that namedhashes view names and stabs to see if it finds a hash.nzf and loads that if it finds it. Dynamically added zones can also be deleted with the delzone command:

    rndc delzone example.aa
    

       addzone zone [class [view]] configuration
	   Add a zone while the	server is running. This	command	requires the
	   allow-new-zones option to be	set to yes. The	configuration string
	   specified on	the command line is the	zone configuration text	that
	   would ordinarily be placed in named.conf.

	   The configuration is	saved in a file	called hash.nzf, where hash is
	   a cryptographic hash	generated from the name	of the view. When
	   named is restarted, the file	will be	loaded into the	view
	   configuration, so that zones	that were added	can persist after a
	   restart.

	   This	sample addzone command would add the zone example.com to the
	   default view:

	   $rndc addzone example.com '{	type master; file "example.com.db";
	   };'

	   (Note the brackets and semi-colon around the	zone configuration
	   text.)

	   See also rndc delzone.

       delzone zone [class [view]]
	   Delete a zone while the server is running. Only zones that were
	   originally added via	rndc addzone can be deleted in this manner.

	   See also rndc addzone





if (nameval == null || (passopt && passval == null)) return; var section_id = null; return this.map.save(function() { var wifi_sections = uci.sections('wireless', 'wifi-iface'); if (replopt.formvalue('_new_') == '1') { for (var i = 0; i < wifi_sections.length; i++) if (wifi_sections[i].device == radioDev.getName()) uci.remove('wireless', wifi_sections[i]['.name']); } if (uci.get('wireless', radioDev.getName(), 'disabled') == '1') { for (var i = 0; i < wifi_sections.length; i++) if (wifi_sections[i].device == radioDev.getName()) uci.set('wireless', wifi_sections[i]['.name'], 'disabled', '1'); uci.unset('wireless', radioDev.getName(), 'disabled'); } var htmodes = radioDev.getHTModes(); if (bss.vht_operation && htmodes && htmodes.indexOf('VHT20') !== -1) { for (var w = bss.vht_operation.channel_width; w >= 20; w /= 2) { if (htmodes.indexOf('VHT'+w) !== -1) { uci.set('wireless', radioDev.getName(), 'htmode', 'VHT'+w); break; } } } else if (bss.ht_operation && htmodes && htmodes.indexOf('HT20') !== -1) { var w = (bss.ht_operation.secondary_channel_offset == 'no secondary') ? 20 : 40; uci.set('wireless', radioDev.getName(), 'htmode', 'HT'+w); } else { uci.remove('wireless', radioDev.getName(), 'htmode'); } uci.set('wireless', radioDev.getName(), 'channel', bss.channel); section_id = next_free_sid(wifi_sections.length); uci.add('wireless', 'wifi-iface', section_id); uci.set('wireless', section_id, 'device', radioDev.getName()); uci.set('wireless', section_id, 'mode', (bss.mode == 'Ad-Hoc') ? 'adhoc' : 'sta'); uci.set('wireless', section_id, 'network', nameval); if (bss.ssid != null) { uci.set('wireless', section_id, 'ssid', bss.ssid); if (bssidval == '1') uci.set('wireless', section_id, 'bssid', bss.bssid); } else if (bss.bssid != null) { uci.set('wireless', section_id, 'bssid', bss.bssid); } if (ssidval != null) uci.set('wireless', section_id, 'ssid', ssidval); if (is_sae) { uci.set('wireless', section_id, 'encryption', 'sae'); uci.set('wireless', section_id, 'key', passval); } else if (is_psk) { for (var i = enc.wpa.length - 1; i >= 0; i--) { if (enc.wpa[i] == 2) { uci.set('wireless', section_id, 'encryption', 'psk2'); break; } else if (enc.wpa[i] == 1) { uci.set('wireless', section_id, 'encryption', 'psk'); break; } } uci.set('wireless', section_id, 'key', passval); } else if (is_wep) { uci.set('wireless', section_id, 'encryption', 'wep-open'); uci.set('wireless', section_id, 'key', '1'); uci.set('wireless', section_id, 'key1', passval); } else { uci.set('wireless', section_id, 'encryption', 'none'); } return network.addNetwork(nameval, { proto: 'dhcp' }).then(function(net) { firewall.deleteNetwork(net.getName()); var zonePromise = zoneval ? firewall.getZone(zoneval).then(function(zone) { return zone || firewall.addZone(zoneval) }) : Promise.resolve(); return zonePromise.then(function(zone) { if (zone) zone.addNetwork(net.getName()); }); }); }).then(L.bind(function() { ui.showModal(null, E('p', { 'class': 'spinning' }, [ _('Loading data…') ])); return this.renderMoreOptionsModal(section_id); }, this)); }; return m2.render().then(L.bind(function(nodes) { ui.showModal(_('Joining Network: %q').replace(/%q/, '"%h"'.format(bss.ssid)), [ nodes, E('div', { 'class': 'right' }, [ E('button', { 'class': 'btn', 'click': ui.hideModal }, _('Cancel')), ' ', E('button', { 'class': 'cbi-button cbi-button-positive important', 'click': ui.createHandlerFn(this, 'handleJoinConfirm', radioDev, bss, m2) }, _('Submit')) ]) ], 'cbi-modal').querySelector('[id="%s"] input[class][type]'.format((passphrase || name).cbid('_new_'))).focus(); }, this));我需要添加保存并应用
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值