ndb 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. .SS "Reverse Domains"
  398. You can also serve reverse lookups (returning the name that
  399. goes with an IP address) by adding an
  400. .B soa=
  401. attribute to the entry defining the root of the reverse space.
  402. For example, to provide reverse lookup for all addresses in
  403. starting with 135.104 you must have a record like:
  404. .IP
  405. .EX
  406. dom=104.135.in-addr.arpa soa=
  407. refresh=3600 ttl=3600
  408. ns=plan9.bell-labs.com
  409. ns=ns1.cs.bell-labs.com
  410. ns=ns2.cs.bell-labs.com
  411. .EE
  412. .LP
  413. Notice the form of the reverse address, i.e., it's the bytes of the
  414. address range you are serving reversed and with
  415. .B .in-addr.arpa
  416. appended. This is a standard form for a domain name in an IPv4 PTR record.
  417. .PP
  418. If such an entry exists in the database, reverse addresses will
  419. automatically be generated from any IP addresses in the database
  420. that are under this root. For example
  421. .IP
  422. .EX
  423. dom=ns1.cs.bell-labs.com ip=135.104.1.11
  424. .EE
  425. .LP
  426. will automatically create both forward and reverse entries for
  427. .B ns1.cs.bell-labs.com .
  428. Unlike other DNS servers, there's no way to generate
  429. inconsistent forward and reverse entries.
  430. .SS "Delegating Name Service Authority"
  431. Delegation of a further subtree to another set of name servers
  432. is indicated by an
  433. .B soa=delegated
  434. attribute.
  435. .IP
  436. .EX
  437. dom=bignose.cs.research.bell-labs.com
  438. soa=delegated
  439. ns=anna.cs.research.bell-labs.com
  440. ns=dj.cs.research.bell-labs.com
  441. .EE
  442. .LP
  443. Nameservers within the delegated domain (as in this example)
  444. must have their IP addresses listed elsewhere in
  445. .I ndb
  446. files.
  447. .SS "Wildcards, MX and CNAME records"
  448. Wild-carded domain names can also be used.
  449. For example, to specify a mail forwarder for all Bell Labs research systems:
  450. .IP
  451. .EX
  452. dom=*.research.bell-labs.com
  453. mx=research.bell-labs.com
  454. .EE
  455. .LP
  456. `Cname' aliases may be established by adding a
  457. .B cname
  458. attribute giving the real domain name;
  459. the name attached to the
  460. .B dom
  461. attribute is the alias.
  462. `Cname' aliases are severely restricted;
  463. the aliases may have no other attributes than
  464. .B dom
  465. and are daily further restricted in their use by new RFCs.
  466. .IP
  467. .EX
  468. cname=anna.cs.bell-labs.com dom=www.cs.bell-labs.com
  469. .EE
  470. .PP
  471. makes
  472. .BI www. ...
  473. a synonym for the canonical name
  474. .BI anna. ... .
  475. .SS "Straddling Server"
  476. Many companies have an inside network
  477. protected from outside access with firewalls.
  478. They usually provide internal `root' DNS servers
  479. (of varying reliability and correctness)
  480. that serve internal domains and pass on DNS queries for
  481. outside domains to the outside, relaying the results
  482. back and caching them for future use.
  483. Some companies don't even let DNS queries nor replies through
  484. their firewalls at all, in either direction.
  485. .PP
  486. In such a situation, running
  487. .B "dns -so"
  488. on a machine that imports access to the outside network via
  489. .B /net.alt
  490. from a machine that straddles the firewalls,
  491. or that straddles the firewalls itself,
  492. will let internal machines query such a machine
  493. and receive answers from outside nameservers for outside addresses
  494. and inside nameservers for inside addresses, giving the appearance
  495. of a unified domain name space,
  496. while bypassing the corporate DNS proxies or firewalls.
  497. This is different from running
  498. .B "dns -s"
  499. and
  500. .B "dns -sRx /net.alt -f /lib/ndb/external"
  501. on the same machine,
  502. which keeps the inside and outside namespaces entirely separate.
  503. .PP
  504. Under
  505. .BR -o ,
  506. several
  507. .I sys
  508. names are significant:
  509. .BR inside-dom ,
  510. .BR inside-ns ,
  511. and
  512. .BR outside-ns .
  513. .I Inside-dom
  514. should contain a series of
  515. .B dom
  516. pairs naming domains internal to the organization.
  517. .I Inside-ns
  518. should contain a series of
  519. .B ip
  520. pairs naming the internal DNS `root' servers.
  521. .I Outside-ns
  522. should contain a series of
  523. .B ip
  524. pairs naming the external DNS servers to consult.
  525. .SS "DNS Queries and Debugging"
  526. .I Ndb/dnsquery
  527. can be used to query
  528. .I ndb/dns
  529. to see how it resolves requests.
  530. .I Ndb/dnsquery
  531. prompts for commands of the form
  532. .IP
  533. .I "domain-name request-type"
  534. .LP
  535. where
  536. .I request-type
  537. can be
  538. .BR ip ,
  539. .BR mx ,
  540. .BR ns ,
  541. .BR cname ,
  542. .BR ptr ....
  543. In the case of the inverse query type,
  544. .BR ptr ,
  545. .I dnsquery
  546. will reverse the ip address and tack on the
  547. .B .in-addr.arpa
  548. for you.
  549. .PP
  550. .I Ndb/dnsdebug
  551. is like
  552. .I ndb/dnsquery
  553. but bypasses the local server.
  554. It communicates via UDP (and sometimes TCP) with the domain name servers
  555. in the same way that the local resolver would and displays
  556. all packets received.
  557. The query can be specified on the command line or
  558. can be prompted for.
  559. The queries look like those of
  560. .I ndb/dnsquery
  561. with one addition.
  562. .I Ndb/dnsdebug
  563. can be directed to query a particular name server by
  564. the command
  565. .BI @ name-server\f1.
  566. From that point on, all queries go to that name server
  567. rather than being resolved by
  568. .IR dnsdebug .
  569. The
  570. .B @
  571. command returns query resolution to
  572. .IR dnsdebug .
  573. Finally, any command preceded by a
  574. .BI @ name-server
  575. sets the name server only for that command.
  576. .PP
  577. Normally
  578. .I dnsdebug
  579. uses the
  580. .B /net
  581. interface and the database file
  582. .BR /lib/ndb/local.
  583. The
  584. .B -f
  585. option supplies the name of the data base file to use.
  586. The
  587. .B -r
  588. option is the same as for
  589. .IR ndb/dns .
  590. The
  591. .B -x
  592. option directs
  593. .I dnsdebug
  594. to use the
  595. .B /net.alt
  596. interface and
  597. .B /lib/ndb/external
  598. database file.
  599. .SH EXAMPLES
  600. .EX
  601. % ndb/query sys helix
  602. sys=helix dom=helix.research.bell-labs.com bootf=/mips/9powerboot
  603. ip=135.104.117.31 ether=080069020427
  604. proto=il
  605. % ndb/dnsquery
  606. > plan9.bell-labs.com ip
  607. plan9.bell-labs.com ip 204.178.31.2
  608. > 204.178.31.2 ptr
  609. 2.31.178.204.in-addr.arpa ptr plan9.bell-labs.com
  610. 2.31.178.204.in-addr.arpa ptr ampl.com
  611. >
  612. .EE
  613. .SH FILES
  614. .TF /lib/ndb/local.*xxx
  615. .TP
  616. .B /env/DNSSERVER
  617. resolver's DNS servers' IP addresses.
  618. .TP
  619. .B /lib/ndb/local
  620. first database file searched
  621. .TP
  622. .B /lib/ndb/local.*
  623. hash files for
  624. .B /lib/ndb/local
  625. .TP
  626. .B /srv/cs
  627. service file for
  628. .I ndb/cs
  629. .TP
  630. .B /net/cs
  631. where
  632. .B /srv/cs
  633. gets mounted
  634. .TP
  635. .B /srv/dns
  636. service file for
  637. .I ndb/dns
  638. .TP
  639. .B /net/dns
  640. where
  641. .B /srv/dns
  642. gets mounted
  643. .SH SOURCE
  644. .B /sys/src/cmd/ndb
  645. .SH SEE ALSO
  646. .IR ndb (2),
  647. .IR ndb (6)
  648. .SH BUGS
  649. .I Ndb
  650. databases are case-sensitive;
  651. ethernet addresses must be in lower-case hexadecimal.