Friday, September 24, 2010

Mapping IP with domain name on local by hosts file

  • อันนี้เป็นการตั้งค่า domain name จับคู่กับ ip แบบดิบๆ บนเครื่องตัวเอง
  • ไม่แน่ใจว่า เราสามารถเรียกการทำแบบนี้ได้หรือไม่ว่า การทำ static dns อ่ะ
  • โดยทำผ่านไฟล์ hosts
  • คือ ปกติเราเข้าเว็บไซต์ เราต้องพิมพ์ url ใช่ปะ
  • ทีนี้เครื่องเรามันจะวิ่งไปถาม DNS Server ว่า url เนี๋ยมัน ip อะไร
  • แต่จริงๆ แล้วขั้นตอนการทำงานของเค้าจะไปตรวจสอบที่ไฟล์ hosts เนี๋ยก่อนเลย
  • ถ้าตรวจสอบไม่เจอมันก็จะไปหาที่ DNS Cache และถ้าไม่เจออีกมันถึงจะวิ่งไปที่ DNS Server
Really important! When your computer wants to connect to a computer by domain name, it always reads a domain name in this order.

a) HOST File - if the domain exist in here, your computer does not go to the DNS Cache. It will use the IP address found in the HOST file.

b) DNS Cache - if the domain exist in here, it does not go to the DNS Server or Servers. It will use the IP address found in the DNS Cache.

c) DNS Server (or Servers) - if the domain does not exist in here, you connection will fail.

Path hosts
  • On a standard UNIX/Linux system (including Apple's Mac OS X) the HOSTS file will generaly be found at
/etc/hosts
  • On Windows systems the location of this file varies.
* Windows 9x - (x):\Windows\Hosts
* Windows XP - (x):\Windows\System32\Drivers\etc\Hosts
* Windows 7 - (x):\Windows\System32\Drivers\etc\Hosts
* Windows 2000 - (x):\WinNT\System32\Drivers\etc\Hosts

Example
192.168.0.1 router.example.com
192.168.0.2 www.example.com
192.168.0.3 foo.example.com

Refer

No comments:

Post a Comment

Popular Posts