IT_Developers/개발기타
localhost, 127.0.0.1은 같을까?
고코더
2022. 2. 13. 08:18
안녕하세요.
고코더 입니다.
"네" 같습니다.
라고 끝내고 싶지만 조금 더 설명을 해보겠습니다.
예약 주소
● 1. 자신의 컴퓨터 환경에 접근하는 방식을 루프백(loopback)이라고 합니다. 그래서 운영체제는 이런 루프백을 위해 고정된 아이피와 호스트네임을 제공하는데 그것이 바로 127.0.0.1과 localhost입니다. 그렇기 때문에 127.0.0.1은 인터넷상에 일반 IP로 쓸 수 없게 되어 있습니다. OS상 가상의 주소입니다.
호스트 파일에서의 단서
●2. HOST 파일을 열어보면 "# 127.0.0.1 localhost"입니다. 호스트 파일에서는 localhost가 바로 127.0.0.1을 바라본다고 주석으로 처리하였습니다. 즉 localhost는 기본적으로 해당 아이피를 가리키고 있습니다. 그것은 곧 루프백입니다.
# 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
CMD에서 ping
● 3. 이번엔 명령 프롬프트에서 ping 127.0.0.1을 날려보면 응답이 돌아옵니다. 이것은 인터넷에서 돌아온 게 아닌 내 컴퓨터의 운영체제에서 돌려준 값입니다.