목차
hosts 파일이란?
정의
- 운영체제의 수준에서 도메인 이름(예: google.com)을 특정 IP 주소로 직접 매핑하는 텍스트 파일.
특징
- 우선순위 : 브라우저나 애플리케이션이 DNS 질의를 하기 전에 먼저 `hosts` 파일을 확인.
- 매핑 포맷 :
IP주소 도메인 이름
- 용도 :
- 특정 도메인을 다른 IP로 강제 매핑 (예: 개발 서버 테스트, 내부망 리디렉션)
- 광고/악성 사이트 차단 (127.0.0.1로 리다이렉트)
- DNS 장애 시 임시 대체 수단
파일 위치
- 리눅스 : /etc/hosts
- 윈도우 : C:\Windows\System32\etc\hosts
예시
127.0.0.1 localhost
192.168.0.10 dev.example.com
구조 다이어그램
[클라이언트] ──> [hosts 파일 확인] ──> [DNS 서버 질의]
└─ 매핑 있으면 즉시 IP 반환
실습
임의의 도메인 이름으로 ping 요청 했을 때, 호스트를 찾을 수 없다.
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
2404:6800:4005:823::200e kimyongjun.com
hosts 파일에 google IPv6 주소를 임의의 도메인 이름으로 매핑한 후 저장.
이전과 다르게 임의의 도메인 이름에 대해 Ping 요청이 전달.
주의
악성코드가 hosts 파일을 변조해 피싱 사이트로 유도하여 발생한 사례들이 있다. Windows 9x 계열에서는 그냥 일반 사용자 권한으로도 hosts 파일을 바꿀 수 있었는데, Window Vista 버전 이후 UAC가 도입되면서 현재는 관리자 권한을 통해 쓰기 접근을 제한하게 되었다. 아래는 피싱 사이트로 유도하여 발생한 실제 사례들이다.
Brazilian “Winehouse” 트로이 목마 : https://www.webroot.com/blog/2011/07/29/brazilian-winehouse-trojan-sends-hotmail-bank-passwords-to-china/
Mydoom warm : https://en.wikipedia.org/wiki/Mydoom
Pharaming 공격 방식 : https://www.proofpoint.com/us/threat-reference/pharming
참고 사이트
Can't modify the Hosts or Lmhosts file - Windows Server
This article provides a workaround for a problem that prevents you from modifying the Hosts file or the Lmhosts file.
learn.microsoft.com
https://en.wikipedia.org/wiki/User_Account_Control
User Account Control - Wikipedia
From Wikipedia, the free encyclopedia Security software User Account Control "Windows Security" alerts in Windows 11 in light mode. From top to bottom: blocked app, app with unknown publisher, app with a known/trusted publisher. User Account Control (UAC)
en.wikipedia.org
https://learn.microsoft.com/en-us/answers/questions/4108674/permission-settings-hosts-file
Permission settings hosts file - Microsoft Q&A
Hi all, Can anyone tell me what the default permissions are for the windows hosts file. I am talking about: 1 ALL APPLICATION PACKAGES 2 ALL RESTRICTED PACKAGES 3 SYSTEM 4 Martin (DEVICE-NAME\Martin) 5 Administrators…
learn.microsoft.com