ndb 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. .TH NDB 8
  2. .SH NAME
  3. query, ipquery, mkhash, mkdb, mkhosts, cs, csquery, dns, dnsquery, dnsdebug \- network database
  4. .SH SYNOPSIS
  5. .B ndb/query
  6. [
  7. .B -f
  8. .I dbfile
  9. ]
  10. .I "attr value"
  11. [
  12. .I rattr
  13. ]
  14. .br
  15. .B ndb/ipquery
  16. .I "attr value"
  17. .I rattr...
  18. .br
  19. .B ndb/mkhash
  20. .I "file attr"
  21. .br
  22. .B ndb/mkdb
  23. .br
  24. .B ndb/mkhosts
  25. [
  26. .I domain
  27. [
  28. .I dbfile
  29. ] ]
  30. .br
  31. .B ndb/cs
  32. [
  33. .B -n
  34. ] [
  35. .B -f
  36. .I dbfile
  37. ] [
  38. .B -x
  39. .I netmtpt
  40. ]
  41. .br
  42. .B ndb/csquery
  43. [
  44. .B -s
  45. ]
  46. [
  47. .I server
  48. [
  49. .I addr...
  50. ]
  51. ]
  52. .br
  53. .B ndb/dns
  54. [
  55. .B -norRs
  56. ] [
  57. .B -a
  58. .I maxage
  59. ] [
  60. .B -f
  61. .I dbfile
  62. ] [
  63. .B -N
  64. .I target
  65. ] [
  66. .B -x
  67. .I netmtpt
  68. ] [
  69. .B -z
  70. .I program
  71. ]
  72. .br
  73. .B ndb/dnsquery
  74. .br
  75. .B ndb/dnsdebug
  76. [
  77. .B -rx
  78. ] [
  79. .B -f
  80. .I dbfile
  81. ] [ [
  82. .BI @ server
  83. ]
  84. .I domain-name
  85. [
  86. .I type
  87. ] ]
  88. .SH DESCRIPTION
  89. The network database holds administrative information used by
  90. network programs such as
  91. .IR dhcpd (8),
  92. .IR ipconfig (8),
  93. .IR con (1),
  94. etc.
  95. .PP
  96. .I Ndb/query
  97. searches the database for an attribute of type
  98. .I attr
  99. and value
  100. .IR value .
  101. If
  102. .I rattr
  103. is not specified, all entries matched by the search are returned.
  104. If
  105. .I rattr
  106. is specified, the value of the first pair with attribute
  107. .I rattr
  108. of all the matched entries is returned.
  109. .PP
  110. .I Ndb/ipquery
  111. uses
  112. .I ndbipinfo
  113. (see
  114. .IR ndb (2))
  115. to search for the values of the attributes
  116. .I rattr
  117. corresponding to the system
  118. with entries of attribute type
  119. .I attr
  120. and
  121. value
  122. .IR value .
  123. .SS "Database maintenance"
  124. .I Ndb/mkhash
  125. creates a hash file for all entries with attribute
  126. .I attr
  127. in database file
  128. .IR file .
  129. The hash files are used by
  130. .I ndb/query
  131. and by the ndb library routines.
  132. .PP
  133. .I Ndb/mkdb
  134. is used in concert with
  135. .IR awk (1)
  136. scripts to convert
  137. uucp systems files and IP host files
  138. into database files.
  139. It is very specific to the situation at Murray Hill.
  140. .PP
  141. When the database files change underfoot,
  142. .I ndb/cs
  143. and
  144. .I ndb/dns
  145. track them properly. Nonetheless, to keep the database searches efficient
  146. it is necessary to run
  147. .I ndb/mkhash
  148. whenever the files are modified.
  149. It may be profitable to control this by a frequent
  150. .IR cron (8)
  151. job.
  152. .PP
  153. .I Ndb/mkhosts
  154. generates a BSD style
  155. .BR hosts ,
  156. .BR hosts.txt ,
  157. and
  158. .B hosts.equiv
  159. files from an ndb data base file specified on the
  160. command line (default
  161. .BR /lib/ndb/local ).
  162. For local reasons the files are called
  163. .BR hosts.1127 ,
  164. .BR astro.txt ,
  165. and
  166. .BR hosts.equiv .
  167. .SS "Connection service"
  168. .I Ndb/cs
  169. is a server used by
  170. .IR dial (2)
  171. to translate network names.
  172. It is started at boot time.
  173. It finds out what networks are configured
  174. by looking for
  175. .B /net/*/clone
  176. when it starts.
  177. It can also be told about networks by writing to
  178. .B /net/cs
  179. a message of the form:
  180. .IP
  181. .B "add net1 net2 ..."
  182. .PP
  183. .I Ndb/cs
  184. also sets the system name in
  185. .B /dev/sysname
  186. if it can figure it out.
  187. The options are:
  188. .TF -n
  189. .TP
  190. .B -f
  191. supplies the name of the data base file to use,
  192. default
  193. .BR /lib/ndb/local .
  194. .TP
  195. .B -n
  196. causes cs to do nothing but set the system name.
  197. .TP
  198. .B -x
  199. specifies the mount point of the
  200. network.
  201. .PD
  202. .PP
  203. .I Ndb/csquery
  204. can be used to query
  205. .I ndb/cs
  206. to see how it resolves addresses.
  207. .I Ndb/csquery
  208. prompts for addresses and prints out what
  209. .I ndb/cs
  210. returns.
  211. .I Server
  212. defaults to
  213. .BR /net/cs .
  214. If any
  215. .I addrs
  216. are specified,
  217. .I ndb/csquery
  218. prints their translations and immediately exits.
  219. The exit status will be nil only if all addresses
  220. were successfully translated.
  221. The
  222. .B -s
  223. flag sets exit status without printing any results.
  224. .SS "Domain name service"
  225. .I Ndb/dns
  226. is a server used by
  227. .I ndb/cs
  228. and by remote systems to translate Internet domain names.
  229. .I Ndb/dns
  230. is started at boot time.
  231. By default
  232. .I dns
  233. serves only requests written to
  234. .BR /net/dns .
  235. Programs must
  236. .I seek
  237. to offset 0 before reading or writing
  238. .B /net/dns
  239. or
  240. .BR /net/cs .
  241. The options are:
  242. .TF -n
  243. .TP
  244. .B -a
  245. sets the maximum time in seconds that an unreferenced
  246. domain name will remain cached.
  247. The default is one hour (3600).
  248. .TP
  249. .B -f
  250. supplies the name of the data base file to use,
  251. default
  252. .BR /lib/ndb/local .
  253. .TP
  254. .B -n
  255. whenever a zone that we serve changes, send UDP NOTIFY
  256. messages to any dns slaves for that zone
  257. (see the
  258. .L dnsslave
  259. attribute below).
  260. .TP
  261. .B -N
  262. sets the goal for the number of domain names cached to
  263. .I target
  264. rather than the default of 8,000.
  265. .TP
  266. .B -o
  267. used with
  268. .BR -s ,
  269. .B -o
  270. causes
  271. .I dns
  272. to assume that it straddles inside and outside networks
  273. and that the outside network is mounted on
  274. .BR /net.alt .
  275. Queries for inside addresses will be sent via
  276. .B /net/udp
  277. (or
  278. .B /net/tcp
  279. in response to truncated replies)
  280. and those for outside addresses via
  281. .B /net.alt/udp
  282. (or
  283. .BR /net.alt/tcp ).
  284. This makes
  285. .I dns
  286. suitable for serving non-Plan-9 systems in an organization with
  287. firewalls, DNS proxies, etc.,
  288. particularly if they don't work very well.
  289. See `Straddling Server' below for details.
  290. .TP
  291. .B -r
  292. act as a resolver only:
  293. send `recursive' queries, asking the other servers
  294. to complete lookups.
  295. If present,
  296. .B /env/DNSSERVER
  297. must be a space-separated list of such DNS servers' IP addresses,
  298. otherwise optional
  299. .IR ndb (6)
  300. .B dns
  301. attributes name DNS servers to forward queries to.
  302. .TP
  303. .B -R
  304. ignore the `recursive' bit on incoming requests.
  305. Do not complete lookups on behalf of remote systems.
  306. .TP
  307. .B -s
  308. also answer domain requests sent to UDP port 53.
  309. .TP
  310. .B -x
  311. specifies the mount point of the
  312. network.
  313. .TP
  314. .B -z
  315. whenever we receive a UDP NOTIFY message, run
  316. .I program
  317. with the domain name of the area as its argument.
  318. .PD
  319. .PP
  320. When the
  321. .B -r
  322. option is specified, the servers used come from the
  323. .I dns
  324. attribute in the database. For example, to specify a set of dns servers that
  325. will resolve requests for systems on the network
  326. .IR mh-net :
  327. .IP
  328. .EX
  329. ipnet=mh-net ip=135.104.0.0 ipmask=255.255.0.0
  330. dns=ns1.cs.bell-labs.com
  331. dns=ns2.cs.bell-labs.com
  332. dom=ns1.cs.bell-labs.com ip=135.104.1.11
  333. dom=ns2.cs.bell-labs.com ip=135.104.1.12
  334. .EE
  335. .LP
  336. The server for a domain is indicated by a database entry containing
  337. both a
  338. .I dom
  339. and a
  340. .I ns
  341. attribute.
  342. .IP
  343. .EX
  344. dom=
  345. ns=A.ROOT-SERVERS.NET
  346. ns=B.ROOT-SERVERS.NET
  347. ns=C.ROOT-SERVERS.NET
  348. dom=A.ROOT-SERVERS.NET ip=198.41.0.4
  349. dom=B.ROOT-SERVERS.NET ip=128.9.0.107
  350. dom=C.ROOT-SERVERS.NET ip=192.33.4.12
  351. .EE
  352. .LP
  353. The last three lines provide a mapping for the
  354. server names to their ip addresses. This is only
  355. a hint and will be superseded from whatever is learned
  356. from servers owning the domain.
  357. .SS "Authoritative Name Servers"
  358. You can also serve a subtree of the domain name space from the local
  359. database. You indicate subtrees that you would like to serve by adding an
  360. .B soa=
  361. attribute to the root entry.
  362. For example, the Bell Labs CS research domain is:
  363. .IP
  364. .EX
  365. dom=cs.bell-labs.com soa=
  366. refresh=3600 ttl=3600
  367. ns=plan9.bell-labs.com
  368. ns=ns1.cs.bell-labs.com
  369. ns=ns2.cs.bell-labs.com
  370. mb=presotto@plan9.bell-labs.com
  371. mx=mail.research.bell-labs.com pref=20
  372. mx=plan9.bell-labs.com pref=10
  373. dnsslave=nslocum.cs.bell-labs.com
  374. dnsslave=vex.cs.bell-labs.com
  375. .EE
  376. .LP
  377. Here, the
  378. .B mb
  379. entry is the mail address of the person responsible for the
  380. domain (default
  381. .BR postmaster ).
  382. The
  383. .B mx
  384. entries list mail exchangers for the domain name and
  385. .B refresh
  386. and
  387. .B ttl
  388. define the area refresh interval and the minimum TTL for
  389. records in this domain.
  390. The
  391. .B dnsslave
  392. entries specify slave DNS servers that should be notified
  393. when the domain changes. The notification also requires
  394. the
  395. .B -n
  396. flag.
  397. .
  398. .SS "Reverse Domains"
  399. You can also serve reverse lookups (returning the name that
  400. goes with an IP address) by adding an
  401. .B soa=
  402. attribute to the entry defining the root of the reverse space.
  403. .PP
  404. For example, to provide reverse lookup for all addresses in
  405. starting with
  406. .L 135.104
  407. or
  408. .LR fd00:: ,
  409. .I ndb
  410. must contain a record like:
  411. .IP
  412. .EX
  413. dom=104.135.in-addr.arpa soa=
  414. dom=d.f.ip6.arpa soa= # special case, rfc 4193
  415. refresh=3600 ttl=3600
  416. ns=plan9.bell-labs.com
  417. ns=ns1.cs.bell-labs.com
  418. ns=ns2.cs.bell-labs.com
  419. .EE
  420. .LP
  421. Notice the form of the reverse address.
  422. For IPv4, it's the bytes of the address range you are serving reversed
  423. and expressed in decimal, and with
  424. .L .in-addr.arpa
  425. appended.
  426. For IPv6, it's the nibbles (4-bit fields) of the address range you are serving
  427. reversed and expressed in hexadecimal, and with
  428. .L .ip6.arpa
  429. appended.
  430. These are the standard forms for a domain name in a PTR record.
  431. .PP
  432. If such an
  433. .B soa
  434. entry exists in the database, reverse addresses will
  435. automatically be generated from any IP addresses in the database
  436. that are under this root. For example
  437. .IP
  438. .EX
  439. dom=ns1.cs.bell-labs.com ip=135.104.1.11
  440. .EE
  441. .LP
  442. will automatically create both forward and reverse entries for
  443. .B ns1.cs.bell-labs.com .
  444. Unlike other DNS servers, there's no way to generate
  445. inconsistent forward and reverse entries.
  446. .
  447. .SS "Delegating Name Service Authority"
  448. Delegation of a further subtree to another set of name servers
  449. is indicated by an
  450. .B soa=delegated
  451. attribute.
  452. .IP
  453. .EX
  454. dom=bignose.cs.research.bell-labs.com
  455. soa=delegated
  456. ns=anna.cs.research.bell-labs.com
  457. ns=dj.cs.research.bell-labs.com
  458. .EE
  459. .LP
  460. Nameservers within the delegated domain (as in this example)
  461. must have their IP addresses listed elsewhere in
  462. .I ndb
  463. files.
  464. .
  465. .SS "Wildcards, MX and CNAME records"
  466. Wild-carded domain names can also be used.
  467. For example, to specify a mail forwarder for all Bell Labs research systems:
  468. .IP
  469. .EX
  470. dom=*.research.bell-labs.com
  471. mx=research.bell-labs.com
  472. .EE
  473. .LP
  474. `Cname' aliases may be established by adding a
  475. .B cname
  476. attribute giving the real domain name;
  477. the name attached to the
  478. .B dom
  479. attribute is the alias.
  480. `Cname' aliases are severely restricted;
  481. the aliases may have no other attributes than
  482. .B dom
  483. and are daily further restricted in their use by new RFCs.
  484. .IP
  485. .EX
  486. cname=anna.cs.bell-labs.com dom=www.cs.bell-labs.com
  487. .EE
  488. .PP
  489. makes
  490. .BI www. ...
  491. a synonym for the canonical name
  492. .BI anna. ... .
  493. .SS "Straddling Server"
  494. Many companies have an inside network
  495. protected from outside access with firewalls.
  496. They usually provide internal `root' DNS servers
  497. (of varying reliability and correctness)
  498. that serve internal domains and pass on DNS queries for
  499. outside domains to the outside, relaying the results
  500. back and caching them for future use.
  501. Some companies don't even let DNS queries nor replies through
  502. their firewalls at all, in either direction.
  503. .PP
  504. In such a situation, running
  505. .B "dns -so"
  506. on a machine that imports access to the outside network via
  507. .B /net.alt
  508. from a machine that straddles the firewalls,
  509. or that straddles the firewalls itself,
  510. will let internal machines query such a machine
  511. and receive answers from outside nameservers for outside addresses
  512. and inside nameservers for inside addresses, giving the appearance
  513. of a unified domain name space,
  514. while bypassing the corporate DNS proxies or firewalls.
  515. This is different from running
  516. .B "dns -s"
  517. and
  518. .B "dns -sRx /net.alt -f /lib/ndb/external"
  519. on the same machine,
  520. which keeps the inside and outside namespaces entirely separate.
  521. .PP
  522. Under
  523. .BR -o ,
  524. several
  525. .I sys
  526. names are significant:
  527. .BR inside-dom ,
  528. .BR inside-ns ,
  529. and
  530. .BR outside-ns .
  531. .I Inside-dom
  532. should contain a series of
  533. .B dom
  534. pairs naming domains internal to the organization.
  535. .I Inside-ns
  536. should contain a series of
  537. .B ip
  538. pairs naming the internal DNS `root' servers.
  539. .I Outside-ns
  540. should contain a series of
  541. .B ip
  542. pairs naming the external DNS servers to consult.
  543. .SS "DNS Queries and Debugging"
  544. .I Ndb/dnsquery
  545. can be used to query
  546. .I ndb/dns
  547. to see how it resolves requests.
  548. .I Ndb/dnsquery
  549. prompts for commands of the form
  550. .IP
  551. .I "domain-name request-type"
  552. .LP
  553. where
  554. .I request-type
  555. can be
  556. .BR ip ,
  557. .BR ipv6 ,
  558. .BR mx ,
  559. .BR ns ,
  560. .BR cname ,
  561. .BR ptr ....
  562. In the case of the inverse query type,
  563. .BR ptr ,
  564. .I dnsquery
  565. will reverse the ip address and tack on the
  566. .B .in-addr.arpa
  567. if necessary.
  568. .PP
  569. .I Ndb/dnsdebug
  570. is like
  571. .I ndb/dnsquery
  572. but bypasses the local server.
  573. It communicates via UDP (and sometimes TCP) with the domain name servers
  574. in the same way that the local resolver would and displays
  575. all packets received.
  576. The query can be specified on the command line or
  577. can be prompted for.
  578. The queries look like those of
  579. .I ndb/dnsquery
  580. with one addition.
  581. .I Ndb/dnsdebug
  582. can be directed to query a particular name server by
  583. the command
  584. .BI @ name-server\f1.
  585. From that point on, all queries go to that name server
  586. rather than being resolved by
  587. .IR dnsdebug .
  588. The
  589. .B @
  590. command returns query resolution to
  591. .IR dnsdebug .
  592. Finally, any command preceded by a
  593. .BI @ name-server
  594. sets the name server only for that command.
  595. .PP
  596. Normally
  597. .I dnsdebug
  598. uses the
  599. .B /net
  600. interface and the database file
  601. .BR /lib/ndb/local.
  602. The
  603. .B -f
  604. option supplies the name of the data base file to use.
  605. The
  606. .B -r
  607. option is the same as for
  608. .IR ndb/dns .
  609. The
  610. .B -x
  611. option directs
  612. .I dnsdebug
  613. to use the
  614. .B /net.alt
  615. interface and
  616. .B /lib/ndb/external
  617. database file.
  618. .SH EXAMPLES
  619. .EX
  620. % ndb/query sys helix
  621. sys=helix dom=helix.research.bell-labs.com bootf=/mips/9powerboot
  622. ip=135.104.117.31 ether=080069020427
  623. proto=il
  624. % ndb/dnsquery
  625. > plan9.bell-labs.com ip
  626. plan9.bell-labs.com ip 204.178.31.2
  627. > 204.178.31.2 ptr
  628. 2.31.178.204.in-addr.arpa ptr plan9.bell-labs.com
  629. 2.31.178.204.in-addr.arpa ptr ampl.com
  630. >
  631. .EE
  632. .SH FILES
  633. .TF /lib/ndb/local.*xxx
  634. .TP
  635. .B /env/DNSSERVER
  636. resolver's DNS servers' IP addresses.
  637. .TP
  638. .B /lib/ndb/local
  639. first database file searched
  640. .TP
  641. .B /lib/ndb/local.*
  642. hash files for
  643. .B /lib/ndb/local
  644. .TP
  645. .B /srv/cs
  646. service file for
  647. .I ndb/cs
  648. .TP
  649. .B /net/cs
  650. where
  651. .B /srv/cs
  652. gets mounted
  653. .TP
  654. .B /srv/dns
  655. service file for
  656. .I ndb/dns
  657. .TP
  658. .B /net/dns
  659. where
  660. .B /srv/dns
  661. gets mounted
  662. .SH SOURCE
  663. .B /sys/src/cmd/ndb
  664. .SH SEE ALSO
  665. .IR ndb (2),
  666. .IR ndb (6)
  667. .SH BUGS
  668. .I Ndb
  669. databases are case-sensitive;
  670. ethernet addresses must be in lower-case hexadecimal.