본문으로 바로가기

bat파일 만들어서 작업환경 구축하기

category Helloworld! 2013. 2. 21. 14:09
1. C:\WINDOWS\system32\drivers\etc의 host파일을 다음과 같이 수정한다.

# Copyright (c) 1993-1999 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

내ip주소입력       localhost
가상으로 쓸 서버 ip주소 입력1   sehee.test1.net
가상으로 쓸 서버 ip주소 입력2   sehee.test2.net
가상으로 쓸 서버 ip주소 입력3  sehee.test3.net

2. hosts_origin과 hosts_local이라는 파일을 추가한다.

3. 위 두파일을 다음과 같이 수정한다.

- hosts_origin

# Copyright (c) 1993-1999 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

내ip주소입력       localhost
가상으로 쓸 서버 ip주소 입력1   sehee.test1.net
#가상으로 쓸 서버 ip주소 입력2   sehee.test2.net
#가상으로 쓸 서버 ip주소 입력3  sehee.test3.net


- hosts_local

# Copyright (c) 1993-1999 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

내ip주소입력       localhost
가상으로 쓸 서버 ip주소 입력1   sehee.test1.net
가상으로 쓸 서버 ip주소 입력2   sehee.test2.net
가상으로 쓸 서버 ip주소 입력3  sehee.test3.net
4. 다음과 같이 두개의 bat파일을 만든다.


- LocalWeb.bat은  localhost와 sehee.test1.net만 쓰는 경우로 설정할 것이다.

- OriginWeb.bat은 sehee.test2.net과 sehee.test3.net도 쓰는 경우로 설정할 것이다.



5. 두 bat파일을 다음과 같이 수정하자.

- OriginWeb.bat

@echo off
copy /Y c:\windows\system32\drivers\etc\hosts_origin c:\windows\system32\drivers\etc\hosts

- LocalWeb.bat

@echo off
copy /Y c:\windows\system32\drivers\etc\hosts_local c:\windows\system32\drivers\etc\hosts


- 설명하자면, LocalWeb.bat을 실행하면 hosts에 hosts_local 내용이 복사된다.

                   OriginWeb.bat을 실행하면 hosts에 hosts_origin 내용이 복사된다.

- /Y는 : 복사할지 않할지 확인 여부를 묻지 않고 바로 복사한다는 명령어이다.