ลูกเล่นของ BIND9 DNS Server!

เทคนิคเล็ก ๆ น้อย ๆ ที่ผมใช้บ่อยมาก ๆ ก็คือ กรณีที่เราต้องการจะได้รายชื่อ

client001 = 192.168.1.101
client002 = 192.168.1.102
client003 = 192.168.1.103
...
...
client100 = 192.168.1.200

จะเห็นว่า ถ้าต้องนั่งพิมพ์นี่ ต้องปาดเหงื่อกันเลยทีเดียว -_-' หรือผู้เชี่ยวชาญบางท่านอาจบอกว่า เขียนสคริปต์เอาก็ได้ ใช่ครับทำอย่างนั้นก็ไม่ผิด แต่ทาง BIND server มีทางเลือกที่ดีกว่าให้ครับผม นั่นก็คือ

Syntax: $GENERATE range lhs type rhs [ comment ]
  • range = start-stop หรือ start-stop/step ถ้าไม่กำหนด step จะเป็น 1
  • lhs = ข้อมูลของ record โดยมีเครื่องหมาย $ แทนตัวเลขที่เรากำหนดใน range และกำหนดค่าเพิ่มเติมได้ในรูป ${offset[,width[,base]]}
    • offset = ตัวเลขที่จะบวกเพิ่ม หรือลบออก จากตัวเลขที่กำหนดใน range
    • width = ความกว้างของตัวเลขที่จะแสดงใน record เช่น 3 ตัวเลขที่ได้คือ 001, 002 เป็นต้น
    • base = ฐานของเลข d สำหรับฐานสิบ, o สำหรับฐานแปด, x หรือ X สำหรับฐานสิบหก
  • type = ชนิดของ record: PTR, CNAME, DNAME, A, AAAA และ NS
  • rhs = ข้อมูลของ record กำหนดเช่นเดียวกับ lhs
  • ตัวอย่าง

    # vi example.com.zone
    
    ...
    $GENERATE 101-200 client${-100,3,d} A 192.168.1.$
    
    # vi example.com.reverse
    
    ...
    $GENERATE 101-200 $ PTR client${-100,3,d}
    
    # /etc/init.d/bind9 restart
    

    ทดสอบลองดูตัวสุดท้ายเลยละกันครับ ถ้าได้ ก็น่าจะได้ทั้งหมด แต่จะทดสอบทั้งหมดก็ไม่ว่ากันครับ อิอิ :)

    # nslookup client100.example.com
    
    Server: 192.168.1.1
    Address: 192.168.1.1#53
    
    Name: client100.example.com
    Address: 192.168.1.200
    
    # nslookup 192.168.1.200
    
    Server: 192.168.1.1
    Address: 192.168.1.1#53
    
    200.1.168.192.in-addr.arpa name = client100.example.com.
    

    ผลที่ได้เป็นไปตามที่กำหนดไว้ข้างต้น ประหยัดแรงไปได้เยอะเลยครับผม

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <blockquote> <img> <h3> <h4> <h5>
  • Lines and paragraphs break automatically.
  • E-Mail addresses are hidden with reCAPTCHA Mailhide.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.