This is G o o g l e's cache of http://www.debianclub.com/node/40 as retrieved on 15 Feb 2007 23:14:46 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?hl=en&q=cache%3Ahttp%3A%2F%2Fwww.debianclub.com%2Fnode%2F40&btnG=Search


Google is neither affiliated with the authors of this page nor responsible for its content.

User login

Links

debianclub.com
debian.org
ubuntuclub.com
blognone.com

Syndicate

Syndicate content

รู้จักกับ ifupdown

ก่อน จะเข้าเรื่อง network admin กัน ขอเรียกน้ำย่อยก่อน ด้วยการทำความรู้จักกับแพกเกจ ifupdown ที่ใช้เป็นกลไกในการตั้งค่าเครือข่ายของ debian แบบลงลึกสักหน่อย

เท้าความเรื่องคำสั่งระดับล่างสักนิด ว่าการที่คุณจะเชื่อมต่อเครื่องของคุณเข้าสู่อินเทอร์เน็ต โดยทั่วไป สิ่งที่จำเป็นต้องเซ็ตก็คือ

  • IP address โดยใช้คำสั่ง ifconfig เช่น
    # ifconfig eth0 192.168.1.2 netmask 255.255.255.0
  • gateway ที่จะเป็นทางผ่านสู่อินเทอร์เน็ต โดยใช้คำสั่ง route เช่น
    # route add default gw 192.168.1.1
  • DNS server ที่จะใช้ resolve ชื่อต่างๆ โดยแก้ที่แฟ้ม /etc/resolv.conf เช่น
    nameserver 192.168.1.1

แต่ถ้าคุณใช้ dynamic IP จาก DHCP server ในเครือข่าย ก็สั่ง:

# dhclient [interface]

เพียงคำสั่งเดียว ก็จะได้ค่าต่างๆ ข้างต้นมาทั้งหมดจาก DHCP server

แต่ถ้าจะมาสั่งอย่างนี้ทุกครั้งที่เปิดเครื่อง ก็จะไม่สะดวก จำเป็นต้องมีการเก็บ config ไว้ในระบบ เพื่อให้เซ็ตค่าโดยอัตโนมัติเลย ซึ่ง debian จะใช้แพกเกจ ifupdown จัดการเรื่องนี้ โดยแฟ้มหลักที่จะเก็บค่า config จะอยู่ที่ /etc/network/interfaces โดยจะกำหนดเป็น "ย่อหน้า" ต่างๆ ขึ้นต้นด้วยคำหลัก ซึ่งที่เราจะได้ใช้บ่อยๆ ก็คือ iface และ auto

auto interface ...
ใช้บอกว่า ให้ up interface ต่างๆ ในรายการนี้ขณะบูต
iface interface inet {static|dhcp}
ใช้ระบุรายละเอียดของ interface ซึ่งถ้าเป็น dynamic IP ผ่าน DHCP ก็จบในบรรทัดได้ แต่ถ้าเป็น static IP ก็จะมีบรรทัดเพิ่มเติมในย่อหน้า คือ

  • address ip-address
  • netmask netmask
  • network network-address
  • broadcast broadcast-address
  • gateway gateway-address

โดยถ้าระบบของคุณคุณใช้ netmask ตาม IP class ตามปกติ ก็สามารถละบรรทัด netmask, network และ broadcast ได้

ตัวอย่างเช่น สำหรับเครื่องลูกข่ายที่ใช้ static IP:

auto eth0
iface eth0 inet static
    address 192.168.1.2
    gateway 192.168.1.1

หรือสำหรับเครื่องลูกข่ายที่ใช้ dynamic IP:

auto eth0
iface eth0 inet dhcp

ตั้งค่าแล้ว กระบวนการบูตก็จะเปิด interface ด้วยค่าที่กำหนดโดยอัตโนมัติ แต่ถ้าต้องการสั่ง up/down interface จากบรรทัดคำสั่ง ก็เพียงแค่:

# ifup eth0

สำหรับการ up และ

# ifdown eth0

สำหรับการ down

ค่า config ต่างๆ ที่กล่าวถึงข้างต้นนี้ ถือว่าเพียงพอสำหรับเครื่องที่เชื่อมต่อ LAN แบบ ethernet โดยทั่วไปแล้ว แต่สำหรับเครือข่ายรูปแบบอื่น รายละเอียดปลีกย่อยในย่อหน้า iface นี่แหละ ที่จะทำให้ ifupdown มีความยืดหยุ่นมาก และมีการเชื่อมรวมกับเครื่องมืออื่นๆ เช่น wireless-tools, resolvconf, ipmasq ด้วย ดังที่จะได้กล่าวถึงในตอนต่อไป