Working bind

This commit is contained in:
notplants 2021-05-12 16:56:49 +02:00
parent 5f2ea71f03
commit f4d6b31125
3 changed files with 71 additions and 11 deletions

16
bash/ns1.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
MYIP="1.1.1.9"
KEY=ddns.key
NS=ns.commoninternet.net
DOMAIN=test2.time.commoninternet.net.
ZONE=time.commoninternet.net
nsupdate -k $KEY -v << EOF
server $NS
zone $ZONE
update delete $DOMAIN A
update add $DOMAIN 30 A $MYIP
send
EOF

View File

@ -0,0 +1,35 @@
Add the following to /etc/bind/named.conf.local:
```
key "ddns-key.dyn.commoninternet.net" {
algorithm hmac-sha256;
secret "yoursecrethere";
};
zone "dyn.commoninternet.net" {
type master;
file "/var/lib/bind/dyn.commoninternet.net";
update-policy {
grant ddns-key.dyn.commoninternet.net subdomain dyn.commoninternet.net;
};
};
```
Add the following to /var/lib/bind/dyn.commoninternet.net:
```
$ORIGIN .
$TTL 30 ; 30 seconds
dyn.commoninternet.net IN SOA ns.commoninternet.net. root.commoninternet.net. (
2016062801 ; serial
3600 ; refresh (1 hour)
600 ; retry (10 minutes)
2600 ; expire (43 minutes 20 seconds)
30 ; minimum (30 seconds)
)
NS ns.commoninternet.net.
```
Note that this file needs to be in /var/lib/bind for bind to have proper write permissions.
You can then add, delete and update subdomains using nsupdate.

View File

@ -12,6 +12,7 @@ use std::net::Ipv4Addr;
use std::str::FromStr;
use trust_dns_client::client::{Client, SyncClient};
use trust_dns_client::udp::UdpClientConnection;
use trust_dns_client::tcp::TcpClientConnection;
use trust_dns_client::op::DnsResponse;
use trust_dns_client::op::update_message;
use trust_dns_client::rr::{DNSClass, Name, RData, Record, RecordType, RecordSet};
@ -21,16 +22,21 @@ use trust_dns_server::authority::{
fn simple_test() {
let address = "127.0.0.1:12323".parse().unwrap();
// let address = "127.0.0.1:12323".parse().unwrap();
let address = "167.99.136.83:53".parse().unwrap();
let conn = UdpClientConnection::new(address).unwrap();
let client = SyncClient::new(conn);
// let conn = TcpClientConnection::new(address).unwrap();
// let client = SyncClient::new(conn);
// Specify the name, note the final '.' which specifies it's an FQDN
let name = Name::from_str("peach.dyn.commoninternet.net").unwrap();
let name = Name::from_str("time.commoninternet.net.").unwrap();
// NOTE: see 'Setup a connection' example above
// Send the query and get a message response, see RecordType for all supported options
println!("++ making query");
let response: DnsResponse = client.query(&name, DNSClass::IN, RecordType::A).unwrap();
println!("++ received response");
// Messages are the packets sent between client and server in DNS, DnsResonse's can be
// dereferenced to a Message. There are many fields to a Message, It's beyond the scope
@ -44,23 +50,26 @@ fn simple_test() {
println!("found: {:?}", answers[0].rdata())
}
fn main() {
let address = "127.0.0.1:12323".parse().unwrap();
fn update_test() {
let address = "167.99.136.83:53".parse().unwrap();
let conn = UdpClientConnection::new(address).unwrap();
let client = SyncClient::new(conn);
// Specify the name, note the final '.' which specifies it's an FQDN
let name = Name::from_str("up.dyn.commoninternet.net").unwrap();
let name = Name::from_str("test.time.commoninternet.net").unwrap();
let record = Record::from_rdata(name.clone(), 8, RData::A(Ipv4Addr::new(127, 0, 0, 10)));
let rrset: RecordSet = record.clone().into();
let zone_origin = Name::from_str("dyn.commoninternet.net").unwrap();
let zone_origin = Name::from_str("time.commoninternet.net").unwrap();
let response: DnsResponse = client.create(rrset, zone_origin).unwrap();
let response: DnsResponse = client.create(rrset, zone_origin).expect("failed to create record");
println!("response: {:?}", response);
// this also produces a response code of 4 (not yet implemented)
}
fn main() {
// simple_test();
update_test();
}