실습)
R1의 f0/1에 설정된 주소로 접속했을때, 아무 템플릿이나 보이도록 해보세요.

기본설정

  • Web(Cloud 1)
    - VMnet1
    - IP: 10.10.1.100 /24
    - GW: 10.10.1.103
    - DNS server: 8.8.8.8
  • R1
    - f0/0: 10.10.1.103
    - f0/1: 211.183.3.100
  • Cloud 2
    - WMnet8
    - IP: 211.183.3.80 /24
    - GW: 211.183.3.2

 

VMnet1 네트워크 설정이 "Host-Only"로 설정되어 있다면, 해당 네트워크는 호스트 시스템(사용자의 PC)과 가상 머신(VM) 간의 통신만 가능하며, 인터넷에 직접적으로 연결되지 않습니다. 이 경우 yum install -y net-tools나 Apache와 같은 패키지를 설치하려면 인터넷에 접근할 수 있는 네트워크가 필요합니다.


Host-Only 네트워크의 특징

  • 가상 머신과 호스트 컴퓨터 간에만 통신 가능.
  • 외부 네트워크(인터넷)에는 접근할 수 없음.

이 설정에서는 인터넷을 통해 패키지를 다운로드하거나 설치할 수 없습니다.

NAT(Network Address Translation)는 VM이 호스트의 인터넷 연결을 공유하도록 설정합니다.


R1 설정

Router#conf t
Router(config)#int f0/0
Router(config-if)#ip add 10.10.1.103 255.255.255.0
Router(config-if)#no sh

Router(config-if)#int f0/1
Router(config-if)#ip add 211.183.3.100 255.255.255.0
Router(config-if)#no sh

PAT 구성 (R1)

Router(config)#access-list 1 permit 10.10.1.0 0.0.0.255
# Source/출발지 정의(access-list N per 192.168.1.0(inside 대역) 0.0.0.255(WM))

R1(config)#int f0/0
R1(config-if)#ip nat inside
R1(config-if)#int f0/1
R1(config-if)#ip nat outside
# 내부(inside) 외부(outside)를 구분

Router(config-if)#ip nat inside source list 1 int f0/1 overload
# NAT 명령(ip nat inside source list N interface (outside) over)

web VM - Xshell

[root@web ~]#ping 211.183.3.2

# PAT가 잘되는지 확인하기위해 web VM에서 211.183.3.0 /24 대역에 존재하는 호스트에 ping 확인

PAT를 통해 R1의 f0/1의 주소인 211.183.3.100으로 변환되는 것을 확인

R1: NAT 확인

Router(config)#do sh ip nat tran

# R1에서 nat가 잘 되는지 확인

R1에서 GW로 통신이 되지만, 외부(8.8.8.8)로 통신이 안되는 것을 확인

Router(config)#do sh ip route

# 8.8.8.8로 통신이 안되는 이유: 라우팅 테이블에 정보가 없기 때문

→ 따라서 default route를 설정해주어야 함!


 

R1: default route 설정

# 넥스트홉은 vmnet8의 GW인 211.183.3.2여야 한다. 왜냐하면 인터넷을 하고 싶기 때문.

Router(config-if)#ip route 0.0.0.0 0.0.0.0 211.183.3.2
# 디폴트루트 설정
# ip route 목적지 IP, SM, 외부의 GW

Router(config)#do ping 8.8.8.8
# PAT 후 내부 웹에서 외부로 통신되는지 확인

web VM - Xshell

[root@web ~]#ping 8.8.8.8

 DNAT 설정(R1)

Router(config-if)#ip nat inside source static tcp 10.10.1.100 80 211.183.3.100 80
# 공인아이피의 80번 포트로 들어왔을때, 10.10.1.100이라는 아이피를 갖는 서버의 80번 포트로 연결

 

내부에서 8.8.8.8로 통신되는것을 확인했다면, VM이 호스트의 인터넷 연결이 가능해집니다!

이제부터 웹 초기 설정 + 템플릿 진행하면 됩니다!


Web 설정

VM web(10.10.1.100)과 연결된 Xshell의 초기세팅

 

1. 방화벽 off

[root@web ~]# systemctl stop firewalld
[root@web ~]# systemctl disable firewalld

 

2. 셀리눅스 off

[root@web ~]# vi /etc/selinux/config

# selinux enforcing을 disabled로 수정

[root@web ~]# systemctl restart network
[root@web ~]# reboot

재부팅

# 재부팅 후에 비활성화가 된걸 확인

 

3. 레포지토리

> cat <<EOF > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=
basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=
basearch&repo=updates&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=
basearch&repo=extras&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=
basearch&repo=centosplus&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=
basearch&repo=contrib&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
> EOF

 

필요한 패키지 설치

[root@web yum.repos.d]# yum install -y net-tools

# ifconfig 명령이 들어있는 패키지 설치

[root@web yum.repos.d]# yum install -y httpd

# apache 설치

root@web yum.repos.d]# systemctl restart httpd
[root@web yum.repos.d]# systemctl enable httpd

# 즉시 동작 및 재부팅 후에도 동작하도록


Web Template 설정

wget: 웹(web)에서 다운로드(get)하는 명령어

[root@web ~]# yum install -y wget

# wget 설치

[root@web ~]# wget https://www.free-css.com/assets/files/free-css-templates/download/page296/oxer.zip

# 임의의 템플릿 링크 주소 지정

[root@web ~]# yum install -y unzip

# unzip 설치

[root@web ~]# unzip oxer.zip

# unzip 실행

 

방법1) 웹루트디렉토리(/var/www/html) 에 ‘템플릿의 내용물’을 복사

[root@web ~]# ls /var/www/html
# 잘 풀렸나 파일 확인

[root@web ~]# rm -rf /var/www/html/*
# /var/www/html에 있는 기존 내용물들을 삭제

[root@web ~]# cp -r ./oxer-html /* /var/www/html
# 템플릿 모든 내용 복사

[root@web ~]# ls /var/www/html
# 잘 복사됐는지 파일 확인

 

이렇게 추가해줬다면,

10.10.1.100을 쳤을때만 실행되었던 웹 템플릿이

211.183.3.100을 쳤을때도 실행되는 것을 확인할 수 있습니다!

 

방법2) 웹루트디렉토리 자체를 변경

[root@web ~]# rm -rf /var/www/html/*

# 기존 내용 삭제

[root@web ~]# mv oxer-html /var/www/html/sub
# 압축 해제한 파일들 /sub으로 이동

[root@web ~]# ls oxer-html /var/www/html/sub
# /sub에 이동 잘됐는지 확인

 

접속했을때 /var/www/html/sub라는 경로로 가기를 바라므로

[root@web ~]# vi /etc/httpd/conf/httpd.conf

# 설정파일 수정

# 사용자들이 내 웹서버에 접속했을때 가는 웹루트디렉토리를 /var/www/html/sub로 변경

[root@web ~]# systemctl restart httpd

# 기능적인 변경사항이 발생하면 재시작으로 반영시켜줘야함

 

이렇게 추가해줬다면,

방법1과 동일한 결과가 나옵니다!