본문으로 바로가기

 1. Samba

 

Samba란 리눅스 공유 서비스를 윈도우에서도 사용하기 위한 서비스를 의미한다. MS와 Intel에서 윈도우시스템이 다른 시스템의 디스크나 프린터 자원을 공유할 수 있도록 SMB(Server Message Block) 프로토콜을 개발하였는데, Samba가 SMB를 이용하여 윈도우와 다른 시스템간의 프린터 및 자료를 공유할 수 있도록 해준다.


samba 서비스는 2개의 데몬으로 구성된다.


 - smbd : 파일 및 프린터 공유, 사용자 확인 및 권한부여 (포트 번호 : 137, 138)
 - nmbd : 클라이언트를 위해 NetBios Nameserver를 지원하고 서비스를 알린다. (포트 번호 : 139)


nbmd는 Samba 서버가 윈도우의 네트워크 이웃으로 탐색되게 하고 사용자가 사용할 수 있는 자원의 목록을 확인할수 있도록 해준다. nmbd 없이 Samba 서버를 운영할 수는 있지만, 이런 경우 서버와 사용자 자원의 Netbios Name을 알아아 한다.

 

 

 

 

2. Samba 패키지 설치 및 서비스 활성화

 

 - Samba 패키지가 설치되었는지 확인한다.


[root@main /root]# rpm -qa | grep samba
samba-winbind-3.6.23-12.el6.x86_64
samba-common-3.6.23-12.el6.x86_64    <- Samba 설정 파일, 유틸리티, 메뉴얼
samba4-libs-4.0.0-64.el6.rc4.x86_64    <- Samba 라이브러리
samba-winbind-clients-3.6.23-12.el6.x86_64
samba-3.6.23-12.el6.x86_64    <- Samba 서버
samba-client-3.6.23-12.el6.x86_64    <- Samba 클라이언트


 

 

 

 - 만약, 설치가 안되어있거나, 업데이트가 필요하면 다음과 같이 설치한다.

 

[root@main /root]# yum -y install samba


 

~ 중간 생략 ~


Updated:
  samba.x86_64 0:3.6.23-25.el6_7

Dependency Updated:
  libsmbclient.x86_64 0:3.6.23-25.el6_7
  samba-client.x86_64 0:3.6.23-25.el6_7
  samba-common.x86_64 0:3.6.23-25.el6_7
  samba-winbind.x86_64 0:3.6.23-25.el6_7
  samba-winbind-clients.x86_64 0:3.6.23-25.el6_7

 

 

[root@main /root]# rpm -qa | grep samba
samba-winbind-clients-3.6.23-25.el6_7.x86_64
samba-3.6.23-25.el6_7.x86_64
samba4-libs-4.0.0-64.el6.rc4.x86_64
samba-winbind-3.6.23-25.el6_7.x86_64
samba-client-3.6.23-25.el6_7.x86_64
samba-common-3.6.23-25.el6_7.x86_64


 

 

 

 - smb, nmb 서비스를 시작한다.

 

[root@main /root]# service smb status
smbd가 정지되었습니다

 

[root@main /root]# service smb start
SMB서비스를 시작하고 있습니다:                             [  OK  ]


 

[root@main /root]# service nmb status
nmbd가 정지되었습니다


[root@main /root]# service nmb start
NMB서비스를 시작하고 있습니다:                             [  OK  ]


 

 

 

 - 재부팅시에도 smb, nmb 서비스가 활성화 되도록 구성한다.


[root@main /root]# chkconfig --list smb
smb             0:해제  1:해제  2:해제  3:해제  4:해제  5:해제  6:해제

 

[root@main /root]# chkconfig smb on
[root@main /root]# chkconfig --list smb
smb             0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제

 

 


 

 

 

 

 

 

 


 

 

 

 

 

 

 


    

 

 

 

 

 

[root@main /root]# chkconfig --list nmb
nmb             0:해제  1:해제  2:해제  3:해제  4:해제  5:해제  6:해제

 

[root@main /root]# chkconfig nmb on


[root@main /root]# chkconfig --list nmb
nmb             0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제


 

 

 

 - smb, nmb 관련 포트 번호를 확인한다.

 

[root@main /root]# egrep '(netbios|microsoft-ds)' /etc/services
netbios-ns      137/tcp                         # NETBIOS Name Service
netbios-ns      137/udp
netbios-dgm   138/tcp                         # NETBIOS Datagram Service
netbios-dgm   138/udp
netbios-ssn     139/tcp                         # NETBIOS session service
netbios-ssn     139/udp
microsoft-ds    445/tcp
microsoft-ds    445/udp


 

 

 

 

3. Samba 설정 파일

 

 - 'smb.conf' 설정 파일에는 Global Setting을 이용하여 Samba 서버 전체 설정을 실시하며, Share Definitions를 이용하여 각각의

   공유에 대한 개별적인 설정을 실시한다.

 

[root@main /root]# ls /etc/samba/
lmhosts  smb.conf  smbusers


 

 

[root@main /root]# vi /etc/samba/smb.conf

 

 


~ 중간 생략 ~

 

 55 #======================= Global Settings ================================
 56
 57 [global]
 58
 59 # ----------------------- Network Related Options -------------------------
 60 #
 61 # workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
 62 #
 63 # server string is the equivalent of the NT Description field
 64 #
 65 # netbios name can be used to specify a server name not tied to the hostname
 66 #
 67 # Interfaces lets you configure Samba to use multiple interfaces
 68 # If you have multiple network interfaces then you can list the ones
 69 # you want to listen on (never omit localhost)
 70 #
 71 # Hosts Allow/Hosts Deny lets you restrict who can connect, and you can
 72 # specifiy it as a per share option as well
 73 #
 74     workgroup = MYGROUP

         윈도우 작업그룹처럼 공유그룹을 지정한다. 클라이언트가 서버에게 요청시 출력하는 이름이다.


 75     server string = Samba Server Version %v

         윈도우에서 확인할때 사용하는 Samba 서버 이름을 지정한다.
 76
 77 ;   netbios name = MYSERVER

         Samba 클라이언트가 윈도우쪽에서 출력될 Netbios 이름을 지정한다.
 78   
 79 ;   interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24

         Samba 서버 서비스를 네트워크 인터페이스별로 제공할때 설정한다. 만약, 설정이 없다면 모든 인터페이

         스에 Samba 서비스를 제공한다.


 80 ;   hosts allow = 127. 192.168.12. 192.168.13.

         Samba 서버에 접속을 허용할 호스트를 지정한다. 만약 접속을 차단하려면 'hosts deny'로 설정한다.


 81
 82 # --------------------------- Logging Options -----------------------------
 83 #
 84 # Log File let you specify where to put logs and how to split them up.
 85 #
 86 # Max Log Size let you specify the max size log files should reach
 87
 88     # logs split per machine
 89     log file = /var/log/samba/log.%m

         Samba 서버에 접속하는 호스트 접속 로그에 대한 기록을 저장하는 로그 파일을 지정한다.


 90     # max 50KB per log file, then rotate
 91     max log size = 50

         로그파일 최대크기를 제한할때 사용한다. 기본값으로 50KB로 설정되어 있으며, 이 크기를 초과하면

         .old 확장자로 저장되고, 새로운 로그 파일이 생성된다. 만약, 0KB로 설정하면 크기 제한이 없어진다.


 92
 93 # ----------------------- Standalone Server Options ------------------------
 94 #
 95 # Scurity can be set to user, share(deprecated) or server(deprecated)
 96 #
 97 # Backend to store user information in. New installations should
 98 # use either tdbsam or ldapsam. smbpasswd is available for backwards
 99 # compatibility. tdbsam requires no further configuration.
100
101     security = user

          보안 관련 옵션이며, 클라이언트가 Samba 서버에 접속할때 인증 레벨을 할당할 수 있다.

          'Domain Members Options', 'Domain Controller Options' 부분에서 관련된 설정을 실시하면 된다.

 

 


 user
 
 Samba 서버에 접속하는 클라이언트는 윈도우 시작시 사용자명과 패스워드로 로그

 인을 한 이후,  Samba 서버에 접속할때도 같은 사용자명과 패스워드를 이용하여 접

 속한다.
 

 share
 
 유효한 사용자명과 패스워드로  Samba 서버에 접속하지 않아도 서버에 접속이 가

 능하다.  Samba 서버 접속 인증이 필요 없을때 사용한다.
 

 server
 
 윈도우 NT와 같은  Samba 서버가 존재해야 한다. 다른  Samba 서버에 사용자명과

 패스워드를 전달하여 올바른지 확인한다.
 

 domain
 
 윈도우 NT 서버가 있어야 가능하며,  Samba 서버가 사용자명과 패스워드를 윈도우

 서버의 도메인 컨트롤러에 전달하여 유효한지 확인한다
 
 

4. Samba 서비스 구성

 


Ex1) Win2003에서 main 공유 자원 접근

 


 - 파일 서버 : Main Eth 0 (172.20.1.1)

 - 클라이언트 : Win2003 NIC (172.20.1.250)

 

 

 

 - 'smb.conf' 설정 파일에서 다음과 같은 설정을 추가 및 변경한다.


 

[root@main /root]# vi /etc/samba/smb.conf


~ 중간 생략 ~

292 # Main Samba Server Configuration
293 [public]
294     comment = Samba Test
295     Path = /samba
296     public = yes
297     writable = yes
298     printable = no

 

: wq!

- 공유 디렉토리 '/samba'를 생성하고, 퍼미션을 조정한다. 또한, 파일 한개를 생성거나 복사한다.


[root@main /root]# mkdir /samba

[root@main /root]# ls -dl /samba
drwxr-xr-x 2 root root 4096 2016-04-18 15:48 /samba

 

 

[root@main /root]# chmod 777 /samba
[root@main /root]# ls -dl /samba
drwxrwxrwx 2 root root 4096 2016-04-18 15:48 /samba

 


[root@main /root]# cp /etc/passwd /samba
[root@main /root]# ls /samba
passwd

 


 

 - smb, nmb 서비스를 재시작한다.

 

[root@main /root]# service smb restart
SMB 서비스를 종료함:                                       [  OK  ]
SMB서비스를 시작하고 있습니다:                             [  OK  ]


 

 

[root@main /root]# service nmb restart
NMB 서비스를 종료함:                                       [  OK  ]
NMB서비스를 시작하고 있습니다:                             [  OK  ]


 

 

 

 - 'testparm' 명령어를 이용하여 'smb.conf' 설정 파일 내용을 점검한다.

 

[root@main /root]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[public]"
WARNING: The security=share option is deprecated
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

(엔터)

 

[global]
        server string = Main Samba Server %v
        log file = /var/log/samba/log.%m
        max log size = 50
        idmap config * : backend = tdb
        hosts allow = 127., 172.20.
        cups options = raw

 

[homes]
        comment = Home Directories
        read only = No
        browseable = No

 

[printers]
        comment = All Printers
        path = /var/spool/samba
        printable = Yes
        print ok = Yes
        browseable = No

 

[public]
        comment = Samba Test
        path = /samba
        read only = No
        guest ok = Yes


 

 

 

 - Samba 계정을 생성한다. 이때, 계정은 '/etc/passwd'에 등록된 계정으로 생성해야 한다.


[root@main /root]# pdbedit -a user1
new password: centos
retype new password: centos
Unix username:        user1
NT username:
Account Flags:        [U          ]
User SID:             S-1-5-21-2890182867-1041611665-2054084988-1000
Primary Group SID:    S-1-5-21-2890182867-1041611665-2054084988-513
Full Name:
Home Directory:       \\main\user1
HomeDir Drive:
Logon Script:
Profile Path:         \\main\user1\profile
Domain:               MAIN
Account desc:
Workstations:
Munged dial:
Logon time:           0
Logoff time:          목, 07  2월 2036 00:06:39 KST
Kickoff time:         목, 07  2월 2036 00:06:39 KST
Password last set:    월, 18  4월 2016 15:15:54 KST
Password can change:  월, 18  4월 2016 15:15:54 KST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

 

[root@main /root]# pdbedit -L
user1:500:


 

 

 

 - Samba 계정 삭제는 다음과 같다.

 

[root@main /root]# pdbedit -x user1
[root@main /root]# pdbedit -L


 

 

 

 - 'smbpasswd' 명령어를 이용한 Samba 계정 생성, 활성화/비활성화, 삭제는 다음과 같다.


[root@main /root]# smbpasswd -a user1      <- 'user1' 계정 생성
New SMB password: centos
Retype new SMB password: centos
Added user user1.


 

 

[root@main /root]# pdbedit -L
user1:500:


 

 

[root@main /root]# smbpasswd -d user1     <- 'user1' 계정 비활성화
Disabled user user1.


 

 

[root@main /root]# smbpasswd -e user1     <- 'user1' 계정 활성화
Enabled user user1.


 

 

[root@main /root]# smbpasswd -x user1     <- 'user1' 계정 삭제

Deleted user user1.


 

 

[root@main /root]# smbpasswd -a user1    <- 'user1' 계정 생성
New SMB password: centos
Retype new SMB password: centos
Added user user1.


 

 

 
[root@main /root]# pdbedit -L
user1:500:

 

 

 

 - 'smbclient' 명령어를 이용하여 공유 유무를 확인하도록 한다.

 

[root@main /root]# smbclient -L localhost -U user1
Enter user1's password: centos
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-25.el6_7]

 

        Sharename       Type      Comment
        ---------           ----        -------
        public             Disk        Samba Test
        IPC$               IPC         IPC Service (Main Samba Server 3.6.23-25.el6_7)
        user1              Disk       Home Directories
        KONICA_MINOLTA_423SeriesPCL:2 Printer   Fax
        Fax:5           Printer   Fax
        HP_Officejet_Pro_8100:3 Printer   HP Officejet Pro 8100
        Hancom_PDF:4    Printer   Hancom PDF
        Microsoft_XPS_Document_Writer:1 Printer   Microsoft XPS Document Writer
        SINDOH_N501_PCL:6 Printer   SINDOH N501 PCL
        Fax:2           Printer   Fax
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-25.el6_7]

 

        Server                     Comment
        ---------                   -------
        MAIN                     Main Samba Server 3.6.23-25.el6_7

 

        Workgroup              Master
        ---------                   -------
        WORKGROUP            MAIN


 

 

 

Win2003의 Network Adapter를 Host -Only로 변경하여 실행한다. 부팅이 완료되었다면, IP 주소를 '172.20.1.250/24', 게이트웨이는 '172.20.0.1'로 설정한다.

 

Win2003에서 ping 172.20.1.1로 Ping 테스트를 실시하고, 다음과 같은 방법을 이용하여 Samba 서버 접속을 실시한다.


window 키 + R -> 실행 - \\172.20.1.1 엔터 -> 'user1' 로그인 실시

 


 


 NTP 서버 & 클라이언트 구성

 

 - main과 clone1에서 NTP 패키지 설치를 실시한다.

 

[root@main /root]# rpm -qa | grep ntp
fontpackages-filesystem-1.41-1.1.el6.noarch
ntpdate-4.2.6p5-1.el6.centos.x86_64
ntp-4.2.6p5-1.el6.centos.x86_64


 

 

[root@main /root]# yum -y install ntp


~ 중간 생략 ~

 

Updated:
  ntp.x86_64 0:4.2.6p5-5.el6.centos.4

Dependency Updated:
  ntpdate.x86_64 0:4.2.6p5-5.el6.centos.4

Complete!

 


[root@main /root]# rpm -qa | grep ntp
ntpdate-4.2.6p5-5.el6.centos.4.x86_64
fontpackages-filesystem-1.41-1.1.el6.noarch
ntp-4.2.6p5-5.el6.centos.4.x86_64


 

 

 

 - main과 clone1에서 ntp 서비스 활성화 상태를 확인한다.


[root@main /root]# service ntpd status
ntpd (pid  11213)를 실행하고 있습니다..


 

 

[root@main /root]# chkconfig --list ntpd
ntpd            0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제


 

 

 

 - main에서 '/etc/ntp.conf' 설정 파일을 vi 편집기를 이용하여 실행한다.

 

[root@main /root]# vi /etc/ntp.conf

 


~ 중간 생략 ~

 

 17 # Hosts on local network are less restricted.
 18 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
 19 restrict 172.20.0.0 mask 255.255.0.0 nomodify notrap
 20
 21 # Use public servers from the pool.ntp.org project.
 22 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 23 # server 0.centos.pool.ntp.org iburst
 24 # server 1.centos.pool.ntp.org iburst
 25 # server 2.centos.pool.ntp.org iburst
 26 # server 3.centos.pool.ntp.org iburst
 27 server 127.127.1.0

 

~ 중간 생략 ~

 

: wq!
 


 

 

 -  테스트를 하기 위해서 main에서 시간을 수동으로 변경하도록 한다.

 

[root@main /root]# date 122514002014

2014. 12. 25. (목) 14:00:00 KST

[

[root@main /root]# date

2014. 12. 25. (목) 14:00:04 KST

 

 

 

 - main에서 ntp 서비스를 재시작하고, NTP 서비스 실시 내용을 확인한다.


[root@main /root]# service ntpd restart
ntpd 종료 중:                                              [  OK  ]
ntpd (을)를 시작 중:                                       [  OK  ]


 

[root@main /root]# pgrep -lf ntpd
11367 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g

 


[root@main /root]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           5 l   14   64    1    0.000    0.000   0.000


 

 

 

 - clone1에서 다음과 같이 '/etc/ntp.conf'에서 NTP 서버를 지정하도록 한다.

 

 

 
[root@clone1 /root]# vi /etc/ntp.conf

 

 ~ 중간 생략 ~

 

 19
 20 # Use public servers from the pool.ntp.org project.
 21 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 22 # server 0.centos.pool.ntp.org iburst
 23 # server 1.centos.pool.ntp.org iburst
 24 # server 2.centos.pool.ntp.org iburst
 25 # server 3.centos.pool.ntp.org iburst
 26 server 172.20.1.1 prefer

~ 중간 생략 ~


: wq!
 


 

 

 

 - clone1에서 ntp 서비스를 재시작하고, NTP 동기화 내용을 확인한다.


[root@clone1 /root]# service ntpd restart
ntpd 종료 중:                                              [  OK  ]
ntpd (을)를 시작 중:                                       [  OK  ]

 


[root@clone1 /root]# pgrep -lf ntpd
4014 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g


 

 

[root@clone1 /root]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

=========================================================

 main            LOCAL(0)         6 u    6   64    1    0.414  -601467   0.000

 

 

[root@clone1 /root]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

=========================================================

*main            LOCAL(0)         6 u   58   64  377    0.245    0.224   0.102


 

 

 

실제 환경에서는 다음과 같이 실제 NTP 서버로부터 동기화 받아서 사용하는 것을 권장한다. (clone1에서도 실시)

 

[root@main /root]# rdate -s time.bora.net

[root@main /root]# date

2016. 11. 20. (일) 16:22:42 KST

 

[root@main /root]# ntpdate -b time.bora.net
20 Nov 16:23:02 ntpdate[23539]: the NTP socket is in use, exitin

 

 

Cisco Network / Linux / 모의 해킹


 태그
 미디어로그
 위치로그
 방명록
 
--------------------------------------------------------------------------------
 


    
Server/Linux III  2016.05.18 11:31
 

 

 


 

 

 


Linux III - 16. Mail 서버 (Sendmail & Dovecot)
 

 

 

1. main, clone1에서 다음과 같이 DNS 테스트를 실시한다.

 

[root@clone1 /root]# vi /etc/resolv.conf


  1 # Generated by NetworkManager
  2
  3
  4 # No nameservers found; try putting DNS servers into your
  5 # ifcfg files in /etc/sysconfig/network-scripts like so:
  6 #
  7 # DNS1=xxx.xxx.xxx.xxx
  8 # DNS2=xxx.xxx.xxx.xxx
  9 # DOMAIN=lab.foo.com bar.foo.com
 10 nameserver 172.20.1.1
 11 nameserver 168.126.63.1

 

: wq!
 

 

 

[root@main /root]# nslookup mail.test.com
Server:         172.20.1.1
Address:        172.20.1.1#53

Name:   mail.test.com
Address: 172.20.1.1

 

 

[root@main /root]# ping -c 3 mail.test.com
PING mail.test.com (172.20.1.1) 56(84) bytes of data.
64 bytes from test.com (172.20.1.1): icmp_seq=1 ttl=64 time=0.102 ms
64 bytes from test.com (172.20.1.1): icmp_seq=2 ttl=64 time=0.044 ms
64 bytes from test.com (172.20.1.1): icmp_seq=3 ttl=64 time=0.045 ms

--- mail.test.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.044/0.063/0.102/0.028 ms

 

 

 

2. Sendmail

 

 - Postfix 이메일 서비스를 종료한다.

 

[root@main /root]# service postfix stop

 

 

 

 - Sendmail 관련 패키지 설치 유무 확인 및 설치 실시

 

[root@main /root]# rpm -q sendmail sendmail-cf
sendmail-8.14.4-9.el6_8.1.x86_64
sendmail-cf 패키지가 설치되어 있지 않습니다

 

 

[root@main /root]# yum -y install sendmail sendmail-cf

 

 

[root@main /root]# rpm -q sendmail sendmail-cf
sendmail-8.14.4-9.el6_8.1.x86_64
sendmail-cf-8.14.4-9.el6_8.1.noarch

 

 

 

 - Sendmail 관련 파일은 '/etc/mail' 디렉토리에서 관리한다.

 

[root@main /root]# ls /etc/mail
Makefile   aliasesdb-stamp  helpfile          mailertable.db  sendmail.mc  trusted-users
access     domaintable      local-host-names  make            submit.cf    virtusertable
access.db  domaintable.db   mailertable       sendmail.cf     submit.mc    virtusertable.db

 

   - sendmail.mc : 'sendmail.cf' 설정 보조 파일

   - sendmail.cf : Sendmail 설정 파일

 

 

 

 - 'sendmail.mc' 파일을 vi 편집기를 이용하여 다음과 같이 설정을 변경하도록 한다.

 

[root@main /root]# vi /etc/mail/sendmail.mc


 ~ 중간 생략 ~

 

 52 TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
 53 define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

// SMTP 인증 기능이며, 이 설정을 주석으러 처리해놓으면 아무나 메일을 전송하는 문제가 발생한다.

 

~ 중간 생략

 

115 dnl #
116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

// Addr=127.0.0.1로 되어있으면, 로컬 호스트(서버 자신)만 SMTP 접속을 허가하고 메일을 발송하게 된다.

그렇기 때문에 Addr=0.0.0.0로 변경하여 다른 호스트로부터 수신하는 메일도 받아서 처리할 수 있도록 해야 한다.


117 dnl #

 

: wq!
 

 

 

 

 - 'm4' 명령어를 이용하여 'sendmail.mc' 설정 내용을 'sendmail.cf' 파일로 이전시킨다.

 

[root@main /root]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

 

 

 

 - 'sendmail.cf' 파일을 vi 편집기를 이용하여 다음과 같이 설정을 변경하도록 한다.

 

[root@main /root]# vi /etc/mail/sendmail.cf


~ 중간 생략 ~

  88
  89 Cwtest.com   <- Cw도메인 이름으로 변경한다.
  90 # file containing names of hosts for which we receive email
  91 Fw/etc/mail/local-host-names
  92 

~ 중간 생략 ~

 

 263
 264 # SMTP daemon options
 265 O DaemonPortOptions=Port=smtp,Addr=0.0.0.0, Name=MTA
 266

 

: wq!
 

 

 

 

 - 메일 릴레이를 위해서 'access' 파일을 vi 편집기를 이용하여 다음과 같이 설정을 변경하도록 한다.

 

[root@main /root]# vi /etc/mail/access


  1 # Check the /usr/share/doc/sendmail/README.cf file for a description
  2 # of the format of this file. (search for access_db in that file)
  3 # The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
  4 # package.
  5 #
  6 # If you want to use AuthInfo with "M:PLAIN LOGIN", make sure to have the
  7 # cyrus-sasl-plain package installed.
  8 #
  9 # By default we allow relaying from localhost...
 10 Connect:localhost.localdomain       RELAY
 11 Connect:localhost           RELAY
 12 Connect:127.0.0.1           RELAY
 13 Connect:test.com            RELAY  <- 지정된 RELAY 대상은 메일서버를 이용하여 메일 송수신 가능
 14 Connect:172.20.             RELAY       만약, 거부하려면 'REJECT'로 변경한다.

 

: wq!
 

 

 

 

- 'makemap' 명령어를 이용하여 Sendmail이 인식할 수 있는 access.db를 생성한다.

 

[root@main /root]# makemap hash /etc/mail/access < /etc/mail/access

 

 

[root@main /root]# ls /etc/mail/access*
/etc/mail/access  /etc/mail/access.db

 

 

[root@main /root]# strings /etc/mail/access.db
RELAY
connect:localhost.localdomain
RELAY
connect:172.20.
RELAY
connect:test.com
RELAY
connect:localhost
RELAY
connect:127.0.0.1

 

 

 

 - 'local-host-names' 파일에 메일을 수신할 도메인 이름을 추가한다.

 

[root@main /root]# vi /etc/mail/local-host-names


  1 # local-host-names - include all aliases for your machine here.
  2 test.com   <- 메일을 수신할 로컬 호스트 도메인 이름을 설정한다.
 

: wq!
 

 

 

 

 - SMTP 인증이 성공되어야 메일을 보낼수 있는 인증 모듈을 시작한다.

 

[root@main /root]# service saslauthd start


[root@main /root]# chkconfig saslauthd on

 

 

[root@main /root]# service sendmail restart
sm-client을 종료하고 있습니다:                             [  OK  ]
sendmail 종료 중:                                          [  OK  ]
sendmail (을)를 시작 중:                                   [  OK  ]
sm-client을 시작하고 있습니다:                             [  OK  ]

 

 

 

 - SMTP 테스트 실시


Ex1) Telnet을 이용한 SMTP 동작 테스트

 

[root@main /root]# telnet localhost 25    
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 test.com ESMTP Sendmail 8.14.4/8.14.4; Tue, 22 Nov 2016 12:07:59 +0900
HELP
214-2.0.0 This is sendmail
214-2.0.0 Topics:
214-2.0.0       HELO    EHLO    MAIL    RCPT    DATA
214-2.0.0       RSET    NOOP    QUIT    HELP    VRFY
214-2.0.0       EXPN    VERB    ETRN    DSN     AUTH
214-2.0.0       STARTTLS
214-2.0.0 For more info use "HELP <topic>".
214-2.0.0 To report bugs in the implementation see
214-2.0.0       http://www.sendmail.org/email-addresses.html
214-2.0.0 For local information send email to Postmaster at your site.
214 2.0.0 End of HELP info
EHLO localhost
250-test.com Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-DELIVERBY
250 HELP
quit
221 2.0.0 test.com closing connection
Connection closed by foreign host.
[root@main /root]#

 

 

 

Ex2) netstat 상태 확인을 이용한 SMTP 동작 여부 확인

 

[root@main /root]# netstat -nlp | grep 25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      4123/sendmail      
tcp        0      0 0.0.0.0:47325               0.0.0.0:*                   LISTEN      1893/rpc.statd     
udp        0      0 172.20.255.255:137          0.0.0.0:*                               2729/nmbd          
udp        0      0 192.168.2.255:137           0.0.0.0:*                               2729/nmbd          
udp        0      0 172.20.255.255:138          0.0.0.0:*                               2729/nmbd          
udp        0      0 192.168.2.255:138           0.0.0.0:*                               2729/nmbd          
unix  2      [ ACC ]     STREAM     LISTENING     21639  3516/gdm-user-switc /tmp/orbit-root/linc-dbc-0-61ef8aca18256
unix  2      [ ACC ]     STREAM     LISTENING     19252  3268/gconfd-2       /tmp/orbit-root/linc-cc4-0-26a82bdc7941d
unix  2      [ ACC ]     STREAM     LISTENING     14047  2554/saslauthd      /var/run/saslauthd/mux


 

 

 

Ex3) 'ps' 명령어를 이용한 Sendmail 동작 상태 확인

 

[root@main /root]# ps -ef | grep sendmail
root      4123     1  0 12:07 ?        00:00:00 sendmail: accepting connections
smmsp     4132     1  0 12:07 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      4155  3031  0 12:08 pts/0    00:00:00 grep sendmail

 

 

 

 

3. Pop3 관련 설정

 

 - Pop3 서비스를 구현하기 위해서 'dovecot' 패케지가 설치하도록 한다.

 

[root@main /root]# yum -y install dovecot

 

[root@main /root]# rpm -qa | grep dovecot
dovecot-2.0.9-22.el6.x86_64

 

 

 

 - 'dovecot.conf' 파일을 vi 편집기를 이용하여 다음과 같이 설정을 변경하도록 한다.

 

[root@main /root]# vi /etc/dovecot/dovecot.conf


~ 중간 생략 ~


 19 # Protocols we want to be serving.
 20 protocols = imap pop3 lmtp  <- pop3 사용이 가능하도록 주석 처리를 삭제한다.
 21
 22 # A comma separated list of IPs or hosts where to listen in for connections.
 23 # "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
 24 # If you want to specify non-default ports or anything more complex,
 25 # edit conf.d/master.conf.
 26 listen = *  <- 메일을 수신할 수 있도록 주석 처리를 삭제하고 *(ANY) 로 변경한다.
 27

 

: wq!
 

 

 

 

 - 사용자 메일 박스를 지정한다.

 

[root@main /root]# vi /etc/dovecot/conf.d/10-mail.conf


 ~ 중간 생략 ~

 

 29 #
 30 mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u
 31

 

: wq!
 

 

 

 

 - SSL 사용 설정을 실시한다.

 

[root@main /root]# vi /etc/dovecot/conf.d/10-ssl.conf


~ 중간 생략 ~


  5 # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
  6 ssl = yes
  7

 

: wq!
 

 

 

 

 - SSL를 사용하므로 암호화된 텍스트 사용 여부를 'no'로 변경한다.

 

[root@main /root]# vi /etc/dovecot/conf.d/10-auth.conf


Linux III - 17. 리눅스 방화벽 (iptables) 
 

 

 

login as: root
root@192.168.1.100's password:
Last login: Sat Apr 16 14:15:34 2016 from 192.168.1.1
[root@main /root]#


 

login as: root
root@192.168.1.101's password:
Last login: Thu Apr  7 14:26:23 2016 from 192.168.1.1
[root@clone1 /root]#


 

login as: root
root@192.168.1.102's password:
Last login: Tue Apr  5 15:31:37 2016 from 192.168.1.1
[root@clone2 /root]#


 

 

 

1. iptables 패키지 설치

 

 - iptables' 패키지 설치 유무를 확인한다.

 

[root@main /root]# rpm -qa | grep iptables
iptables-ipv6-1.4.7-14.el6.x86_64
iptables-1.4.7-14.el6.x86_64

 

 

[root@main /root]# yum list iptables
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.tt.co.kr
 * extras: centos.mirror.cdnetworks.com
 * updates: centos.mirror.cdnetworks.com
Installed Packages
iptables.x86_64                 1.4.7-14.el6                  @anaconda-CentOS-201410241409.x86_64/6.6


Available Packages
iptables.i686                   1.4.7-16.el6                  base
iptables.x86_64                 1.4.7-16.el6                  base


 

 

 - 'iptables' 패키지를 설치한다.


[root@main /root]# yum -y install iptables


 

 

[root@main /root]# rpm -qa | grep iptables
iptables-1.4.7-16.el6.x86_64
iptables-ipv6-1.4.7-16.el6.x86_64


 

 

 

 

2. iptables 체인 및 제어 유형

 

iptables는 리눅스 방화벽을 의미하며, 다음과 같이 기본적으로 3개의 논리적인 체인(Chain)으로 구성되며, 관리자에 의해서 수동으로 신규 생성이 가능하다.  이때 체인이란 방화벽에서 사용되는 Rule이 등록되는 곳을 의미한다.

 

[root@main /root]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination


 

 


 체인 유형
 
내용
 

 INPUT
 
 입력되는 패켓에 대한 설정을 위한 체인
 

 FORWARD
 
 경유하는 패켓에 대한 설정을 위한 체인
 

 OUTPUT
 
 출력되는 패켓에 대한 설정을 위한 체인
 

 사용자 정의
 
 관리자가 수동으로 설정하는 체인
 


 

 

iptables는 패켓을 제어하기 위해서 다음과 같은 4가지 동작을 실시한다.

 

 


 동작 유형
 
내용
 

ACCEPT
 
 패켓을 허용한다.
 

DROP
 
 패켓을 드랍한다.
 

 REJECT
 
 접근하는 패켓을 차단하고, 접근 경고 메세지를 출력한다.
 

 LOG
 
 룰이 매칭될 경우, 로그를 발생한다.
 


 

 

 

[참고] iptables 방화벽은 Cisco의 ACL과 개념이 비슷하다.

 

 

 

 

 

3. iptables 명령어

 

 1) 체인 관련 명령어

 

 - 'N' 옵션 : 신규 체인을 생성한다.

 

[root@main /root]# iptables -N NEW
[root@main /root]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

 

Chain NEW (0 references)
target     prot opt source               destination


 

 

 - 'X' 옵션 : 비어있는 체인을 삭제한다.

 

[root@main /root]# iptables -X NEW
[root@main /root]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination


 

 

 - 'P' 옵션 : 체인 정책을 설정한다. ('putty'에서 실행하면, SSH 접속이 차단되므로, Xwindow에서 진행할 것)


[root@main /root/바탕화면]# iptables -P INPUT DROP
[root@main /root/바탕화면]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination   

    

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination   

    

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

      


[root@main /root/바탕화면]# iptables -P INPUT ACCEPT


 

 

 - 'L' 옵션 : iptables 내용을 확인한다.


[root@main /root]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination


 

 

[root@main /root]# iptables -L -v
Chain INPUT (policy ACCEPT 71 packets, 14132 bytes)
 pkts bytes target     prot opt in     out     source               destination      

               

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination    

                 

Chain OUTPUT (policy ACCEPT 59 packets, 6716 bytes)
 pkts bytes target     prot opt in     out     source               destination   

 

 

[root@main /root]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination


 


[root@main /root]# iptables -L INPUT -v
Chain INPUT (policy ACCEPT 146 packets, 19576 bytes)
 pkts bytes target     prot opt in     out     source               destination


 

 

 - 'F' 옵션 : 체인 안에 있는 룰을 삭제한다.


[root@main /root]# iptables -A INPUT -p icmp -j DROP
[root@main /root]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       icmp --  anywhere             anywhere

 


[root@main /root]# iptables -F INPUT
[root@main /root]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination


 

 

 2) 체인 룰 관련 명령어

 

 - 'A' 옵션 : 체인에 룰을 추가한다. 이때, 설정된 순번대로 정렬되며, 검사가 진행된다.


[root@main /root]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[root@main /root]# iptables -A INPUT -p tcp --sport 80 -j ACCEPT
[root@main /root]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http


 

 

 - 'I' 옵션 : 체인에 룰을 추가할 경우, 맨 첫번째 항목에 추가한다.

 

[root@main /root]# iptables -I INPUT -p icmp -j DROP
[root@main /root]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http


 

 

 - 'D' 옵션 : 체인 룰을 삭제한다.


[root@main /root]# iptables -D INPUT -p icmp -j DROP
[root@main /root]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http


 

 

 

 3) 필터링 명령어

 

 - 'j' 옵션 : 특정한 정책을 설정한다.

 

 - 's' 옵션 : 출발지 IP 주소를 지정한다.

 

 - 'd' 옵션 : 목적지 IP 주소를 지정한다.

 

 - 'sport' 옵션 : 출발지 포트를 지정한다.

 

 - 'dport' 옵션 : 목적지 포트를 지정한다.

 

 - 'p' 옵션 : 프로토콜을 지정한다.

 

 - 'i' 옵션 : 패켓이 입력되는 인터페이스를 설정한다. 주로 INPUT, OUTPUT 체인에서 사용한다.

 

 - 'o' 옵션 : 패켓이 출력되는 인터페이스를 설정한다. 주로 OUTPUT, FORWARD 체인에서 사용한다.

 

 - 't' 옵션 : 테이블을 선택할때 사용한다. (테이블 유형 : filter, nat, mangle)

 

 

[root@main /root]# iptables -D INPUT -p tcp --dport 80 -j ACCEPT
[root@main /root]# iptables -D INPUT -p tcp --sport 80 -j ACCEPT
[root@main /root]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination


 

 

 

 

4. iptables 실습 환경 구성

 

 - 로그 동작 확인

 

[root@main /root]# tail -f /var/log/messages /var/log/secure
~ 중간 생략 ~

(ctrl+c)

 

 

 - nmap 설치 (clone1, clone2에서도 설치 실시)

 

[root@main /root]# yum -y install nmap


 

 

[root@main /root]# rpm -qa | grep nmap
nmap-5.51-4.el6.x86_64


 

 

 - 'Putty'를 이용한 텔넷, SSH 접속 허용 및 나머지 Drop 실시

 

[root@main /root]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
[root@main /root]# iptables -P INPUT DROP

 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh

 

 

[root@main /root]# service iptables status
테이블: filter
Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22

 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination

 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination


 

 

 - 재부팅되어도 설정이 적용될 수 있도록 iptables 설정 저장 실시

 

[root@main /root]# ls -l /etc/sysconfig/iptables
-rw-------. 1 root root 476 2016-03-11 02:36 /etc/sysconfig/iptables

 


[root@main /root]# service iptables save
iptables: 방화벽 규칙을 /etc/sysconfig/iptables에 저장 중: [  OK  ]

 


[root@main /root]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Wed May 18 14:02:01 2016
*filter
:INPUT DROP [2:160]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [131:13156]
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
COMMIT
# Completed on Wed May 18 14:02:01 2016


 

 

 - 저장된 설정 적용 확인 ('putty'에서 실행하면, SSH 접속이 차단되므로, Xwindow에서 진행할 것)

 

[root@main /root/바탕화면]# iptables -F

[root@main /root/바탕화면]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination        

 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination    

   

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination       


 

 

[root@main /root/바탕화면]# service iptables stop
iptables: 체인을 ACCEPT 규칙으로 설정 중:  filter          [  OK  ]
iptables: 방화벽 규칙을 지웁니다:                          [  OK  ]
iptables: 모듈을 언로드하는 중:                            [  OK  ]


 

 

[root@main /root/바탕화면]# service iptables start
iptables: 방화벽 규칙 적용 중:                             [  OK  ]


 

 

[root@main /root/바탕화면]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination        
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh

 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination   

    

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination     


 

 

 - iptables 서비스 중지 및 재시작

 

[root@main /root/바탕화면]# service iptables stop
iptables: 체인을 ACCEPT 규칙으로 설정 중:  filter          [  OK  ]
iptables: 방화벽 규칙을 지웁니다:                          [  OK  ]
iptables: 모듈을 언로드하는 중:                            [  OK  ]

 

[root@main /root/바탕화면]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination    

   

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination   

    

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        


 

 

[root@main /root/바탕화면]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Wed May 18 14:02:01 2016
*filter
:INPUT DROP [2:160]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [131:13156]
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT

COMMIT
# Completed on Wed May 18 14:02:01 2016


 

 

[root@main /root/바탕화면]# service iptables start
iptables: 방화벽 규칙 적용 중:                             [  OK  ]


 

 

 - 재부팅시 iptables 서비스 자동 시작 설정 실시

 

[root@main /root/바탕화면]# chkconfig --list iptables
iptables        0:해제 1:해제 2:해제 3:해제 4:해제 5:해제 6:해제

 

 

[root@main /root/바탕화면]# chkconfig iptables on

 


[root@main /root/바탕화면]# chkconfig --list iptables
iptables        0:해제 1:해제 2:활성 3:활성 4:활성 5:활성 6:해제

 


[root@main /root/바탕화면]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination        
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh

 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination      

 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        

 

 

- clone1에서 main으로 접속 가능한 서비스를 확인하도록 한다.

 

[root@clone1 /root]# nmap 172.20.1.1

Starting Nmap 5.51 ( http://nmap.org ) at 2016-05-18 14:47 KST
Nmap scan report for main (172.20.1.1)
Host is up (0.00062s latency).
Not shown: 999 filtered ports
PORT   STATE SERVICE
22/tcp open  ssh
MAC Address: 00:0C:29:E9:9C:40 (VMware)

 

Nmap done: 1 IP address (1 host up) scanned in 4.65 seconds

 

 

 

 - clone1에서 main으로 ping, telnet 차단 확인


[root@clone1 /root]# ping -c 1 172.20.1.1
PING 172.20.1.1 (172.20.1.1) 56(84) bytes of data.

 

--- 172.20.1.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 10000ms

 


[root@clone1 /root]# telnet 172.20.1.1
Trying 172.20.1.1...

(ctrl+c)

 

 

 

 

5. iptables 실습

 

Ex1) 특정 인터페이스로 입력되는 패켓 허용

 

[root@main /root]# ping -c 1 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

 

--- 127.0.0.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 10000ms

 


[root@main /root]# iptables -A INPUT -i lo -j ACCEPT


 

 

[root@main /root]# iptables -L INPUT -v
Chain INPUT (policy DROP 850 packets, 37400 bytes)
 pkts bytes target     prot opt in     out     source               destination
 3118  246K ACCEPT   tcp  --  any    any    anywhere           anywhere            tcp dpt:ssh
    0     0 ACCEPT      all  --    lo     any     anywhere           anywhere
 

 

 

[root@main /root]# ping -c 1 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.102 ms

 

--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.102/0.102/0.102/0.000 ms


 

 

 

Ex2) Main으로 접근하는 DNS 요청 허용

 

[root@clone1 /root]# nslookup www.test.com
Server:         168.126.63.1
Address:        168.126.63.1#53

 

Non-authoritative answer:
Name:   www.test.com
Address: 69.172.200.235


 


[root@main /root]# iptables -A INPUT -p udp --dport 53 -j ACCEPT


 

 

[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     all  --  anywhere             anywhere
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain

 

 

[root@clone1 /root]# nslookup www.test.com
Server:         172.20.1.1
Address:        172.20.1.1#53

Name:   www.test.com
Address: 172.20.1.1


 

 

 

Ex3) main에서 나갔다가 돌아오는 DNS 응답 허용


[root@main /root]# nslookup www.naver.com
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached


 


[root@main /root]# iptables -A INPUT -p udp --sport 53 --dport 1024:65535 -j ACCEPT


 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     all  --  anywhere             anywhere
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            udp spt:domain dpts:1024:65535

 

[root@main /root]# nslookup www.naver.com
Server:         168.126.63.1
Address:        168.126.63.1#53

 

Non-authoritative answer:
www.naver.com   canonical name = www.naver.com.nheos.com.
Name:   www.naver.com.nheos.com
Address: 202.179.177.22
Name:   www.naver.com.nheos.com
Address: 125.209.222.141


 


 

Ex4) main으로 접근하는 ICMP 허용

 

[root@clone1 /root]# ping -c 1 172.20.1.1
PING 172.20.1.1 (172.20.1.1) 56(84) bytes of data.

 

--- 172.20.1.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 10000ms

 

 

[root@main /root]# iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT


 

 

[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     all  --  anywhere             anywhere
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            udp spt:domain dpts:1024:65535
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request

 

 

[root@clone1 /root]# ping -c 1 172.20.1.1                                      

PING 172.20.1.1 (172.20.1.1) 56(84) bytes of data.
64 bytes from 172.20.1.1: icmp_seq=1 ttl=64 time=0.576 ms

--- 172.20.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.576/0.576/0.576/0.000 ms


 

 

 

Ex5) main에서 나갔다가 돌아오는 ICMP 허용

 

[root@main /root]# ping -c 1 172.20.1.101
PING 172.20.1.101 (172.20.1.101) 56(84) bytes of data.

 

--- 172.20.1.101 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 10000ms

 


[root@main /root]# iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT

 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     all  --  anywhere             anywhere
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            udp spt:domain dpts:1024:65535
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request
ACCEPT     icmp --  anywhere             anywhere            icmp echo-reply


 

 

[root@main /root]# ping -c 1 172.20.1.101
PING 172.20.1.101 (172.20.1.101) 56(84) bytes of data.
64 bytes from 172.20.1.101: icmp_seq=1 ttl=64 time=0.435 ms

 

--- 172.20.1.101 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.435/0.435/0.435/0.000 ms


 


[root@main /root]# ping -c 1 168.126.63.1
PING 168.126.63.1 (168.126.63.1) 56(84) bytes of data.
64 bytes from 168.126.63.1: icmp_seq=1 ttl=128 time=2.22 ms

 

--- 168.126.63.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 2.220/2.220/2.220/0.000 ms


 

 

 

Ex6) main으로 접근하는 clone1 Telnet만 허용

 

[root@clone1 /root]# telnet 172.20.1.1
Trying 172.20.1.1...
(ctrl + c)


 

 

[root@main /root]# iptables -A INPUT -s 172.20.1.101 -p tcp --dport 23 -j ACCEPT

 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT     all  --   anywhere            anywhere
ACCEPT     udp  --  anywhere           anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere           anywhere            udp spt:domain dpts:1024:65535
ACCEPT     icmp --  anywhere           anywhere            icmp echo-request
ACCEPT     icmp --  anywhere           anywhere            icmp echo-reply
ACCEPT     tcp  --  clone1                anywhere            tcp dpt:telnet

 

 

[root@clone1 /root]# telnet 172.20.1.1
Trying 172.20.1.1...
Connected to 172.20.1.1.
Escape character is '^]'.
CentOS release 6.6 (Final)
Kernel 2.6.32-504.el6.x86_64 on an x86_64
login: user1
Password: centos
Last login: Wed May 18 14:36:44 from clone1
[user1@main /home/user1]$
[user1@main /home/user1]$ exit
logout
Connection closed by foreign host.

 


[root@clone2 /root]# telnet 172.20.1.1
Trying 172.20.1.1...

(ctrl+c)

 

 

 

Ex7) main에서 나갔다가 돌아오는 telnet 허용

 

[root@main /root]# telnet 172.20.1.101
Trying 172.20.1.101...

(ctrl+c)


 

 

[root@main /root]# iptables -A INPUT -d 172.20.1.1 -p tcp --sport 23 -j ACCEPT


 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT     all  --   anywhere            anywhere
ACCEPT     udp  --  anywhere           anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere           anywhere            udp spt:domain dpts:1024:65535
ACCEPT     icmp --  anywhere           anywhere            icmp echo-request
ACCEPT     icmp --  anywhere           anywhere            icmp echo-reply
ACCEPT     tcp  --   clone1               anywhere            tcp dpt:telnet
ACCEPT     tcp  --   anywhere            test.com            tcp spt:telnet

 


[root@main /root]# telnet 172.20.1.101
Trying 172.20.1.101...
Connected to 172.20.1.101.
Escape character is '^]'.
CentOS release 6.6 (Final)
Kernel 2.6.32-504.el6.x86_64 on an x86_64
login: user1
Password: centos
[user1@clone1 /home/user1]$ exit
logout
Connection closed by foreign host.

 

 

 

Ex8) main으로 접근하는 HTTP, HTTPs 허용

 

[root@main /root]# iptables -A INPUT -d 172.20.1.1 -p tcp --dport 80 -j ACCEPT


[root@main /root]# iptables -A INPUT -d 172.20.1.1 -p tcp --dport 443 -j ACCEPT


 

 

[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT     all  --    anywhere           anywhere
ACCEPT     udp  --  anywhere           anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere           anywhere            udp spt:domain dpts:1024:65535
ACCEPT     icmp --  anywhere           anywhere            icmp echo-request
ACCEPT     icmp --  anywhere           anywhere            icmp echo-reply
ACCEPT     tcp  --  clone1                anywhere            tcp dpt:telnet
ACCEPT     tcp  --  anywhere             test.com            tcp spt:telnet
ACCEPT     tcp  --  anywhere             test.com            tcp dpt:http

ACCEPT     tcp  --  anywhere             test.com            tcp dpt:https


 

[clone1에서 main 웹-접속 실시]

 

 

 

 

 

 

Ex8) main에서 나갔다가 돌아오는 http 허용

 

[root@main /root]# iptables -A INPUT -p tcp --sport 80 -j ACCEPT
[root@main /root]# iptables -A INPUT -p tcp --sport 443 -j ACCEPT

 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT     all  --   anywhere            anywhere
ACCEPT     udp  --  anywhere           anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere           anywhere            udp spt:domain dpts:1024:65535
ACCEPT     icmp --  anywhere           anywhere            icmp echo-request
ACCEPT     icmp --  anywhere           anywhere            icmp echo-reply
ACCEPT     tcp  --  clone1                anywhere            tcp dpt:telnet
ACCEPT     tcp  --  anywhere             test.com             tcp spt:telnet
ACCEPT     tcp  --  anywhere             test.com             tcp dpt:http
ACCEPT     tcp  --  anywhere             test.com             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:https


 

[main에서 구글 접속 실시]

 

 

 

 

[root@main /root]# service iptables restart
iptables: 체인을 ACCEPT 규칙으로 설정 중:  filter          [  OK  ]
iptables: 방화벽 규칙을 지웁니다:                          [  OK  ]
iptables: 모듈을 언로드하는 중:                            [  OK  ]
iptables: 방화벽 규칙 적용 중:                             [  OK  ]


 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh


 

 

 

Ex9) 'm' 옵션 & 'ESTABLISHED' 기능 (Stateful 방화벽 기능)

 

[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh


 

[root@main /root]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[root@main /root]# iptables -A INPUT -p all -j REJECT

 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:http
REJECT      all  --   anywhere            anywhere            reject-with icmp-port-unreachable

 

 

 - clone1에서 main으로 http 접속만 허용되며, ICMP 및 Telnet을 포함한 나머지 패켓들은 접근이 불가능하다.

 

[root@clone1 /root]# ping -c 1 172.20.1.1
PING 172.20.1.1 (172.20.1.1) 56(84) bytes of data.
From 172.20.1.1 icmp_seq=1 Destination Port Unreachable

 

--- 172.20.1.1 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

 


[root@clone1 /root]# telnet 172.20.1.1
Trying 172.20.1.1...
telnet: connect to address 172.20.1.1: Connection refused


 


[root@clone1 /root]# telnet 172.20.1.1 80
Trying 172.20.1.1...
Connected to 172.20.1.1.
Escape character is '^]'.
^
<h1> Welcome to www.test.com <h1>

 

Connection closed by foreign host.


 


 - main에서 나갔다가 돌아오는 패켓을 허용하는 설정이 없기 때문에, clone1로부터 수신하는 응답이 차단된다.

 

[root@main /root]# ping -c 1 172.20.1.101
PING 172.20.1.101 (172.20.1.101) 56(84) bytes of data.

--- 172.20.1.101 ping statistics ---


1 packets transmitted, 0 received, 100% packet loss, time 10000ms

 


[root@main /root]# telnet 172.20.1.101
Trying 172.20.1.101...
(ctrl+c)


 

 

 - main에서 'm' 옵션과 'ESTABLISHED' 기능을 이용하여 다음과 같은 룰 항목을 가장 앞에 추가하도록 한다.

 

 

[root@main /root]# iptables -I INPUT -m state --state ESTABLISHED,RELATED -p all -j ACCEPT

 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere           tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere           tcp dpt:http
REJECT      all  --  anywhere             anywhere            reject-with icmp-port-unreachable

 

 

 - 'ESTABLISHED' 기능을 이용하면 되돌아오는 패켓을 허용하기 때문에 main에서 clone1으로 ICMP, Telnet이 가능하다.

 

[root@main /root]# ping -c 1 172.20.1.101
PING 172.20.1.101 (172.20.1.101) 56(84) bytes of data.
64 bytes from 172.20.1.101: icmp_seq=1 ttl=64 time=0.332 ms

 

--- 172.20.1.101 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.332/0.332/0.332/0.000 ms

 

[root@main /root]# telnet 172.20.1.101
Trying 172.20.1.101...
Connected to 172.20.1.101.
Escape character is '^]'.
CentOS release 6.6 (Final)
Kernel 2.6.32-504.el6.x86_64 on an x86_64
login: user1
Password: centos
Last login: Wed May 18 16:19:17 from clone2
[user1@clone1 /home/user1]$ exit
logout
Connection closed by foreign host.

 

 

[참고] RELATED : 새 연결을 시도하는 패켓이지만 이전 연결과 관련있는 패캣

 

  Ex) FTP DATA 전송


  FTP 서비스가 방화벽에서 허용되어 있고 연결되어 있는 상태인 경우, FTP DATA 패켓도 허용이 된다.

 

 

 

Ex10) LOG 동작 확인

 

 - main에서 LOG 설정 룰을 항목을 가장 앞에 추가하도록 한다.

 

[root@main /root]# iptables -I INPUT -p icmp --icmp-type echo-request -j LOG


 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
LOG         icmp --  anywhere           anywhere            icmp echo-request LOG level warning
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:http
REJECT      all  --  anywhere             anywhere            reject-with icmp-port-unreachable


 


 - main에서 다음과 같이 실시간 로그 확인을 실행한다.

 

[root@main /root]# tail -f /var/log/messages /var/log/secure
~ 중간 생략 ~

 

 

 - clone1에서 main으로 Ping을 실시한다.

 

[root@clone1 /root]# ping -c 3 172.20.1.1
PING 172.20.1.1 (172.20.1.1) 56(84) bytes of data.
From 172.20.1.1 icmp_seq=1 Destination Port Unreachable
From 172.20.1.1 icmp_seq=2 Destination Port Unreachable
From 172.20.1.1 icmp_seq=3 Destination Port Unreachable

 

--- 172.20.1.1 ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2002ms

 

 

 - main에서 로그를 확인한다.

 

[root@main /root]# tail -f /var/log/messages /var/log/secure
~ 중간 생략 ~


==> /var/log/messages <==
May 18 17:28:43 main kernel: IN=eth0 OUT= MAC=00:0c:29:e9:9c:40:00:0c:29:00:2d:b7:08:00 SRC=172.20.1.101 DST=172.20.1.1 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=6671 SEQ=1
May 18 17:28:44 main kernel: IN=eth0 OUT= MAC=00:0c:29:e9:9c:40:00:0c:29:00:2d:b7:08:00 SRC=172.20.1.101 DST=172.20.1.1 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=6671 SEQ=2
May 18 17:28:45 main kernel: IN=eth0 OUT= MAC=00:0c:29:e9:9c:40:00:0c:29:00:2d:b7:08:00 SRC=172.20.1.101 DST=172.20.1.1 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=6671 SEQ=3

(ctrl+c)

 

 

 

Ex11) SSH 접근 허용 룰을 제외한 나머지 룰을 삭제하도록 한다.

 

[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
LOG        icmp --  anywhere           anywhere            icmp echo-request LOG level warning
ACCEPT    all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT    tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT    tcp  --  anywhere            anywhere            tcp dpt:http
REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable

 

 

[root@main /root]# iptables -D INPUT 5
[root@main /root]# iptables -D INPUT 4
[root@main /root]# iptables -D INPUT 2
[root@main /root]# iptables -D INPUT 1


 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh


 

 

 

Ex12) 스크립트를 이용한 iptables 구성


[root@main /root]# mkdir -p /root/bin
[root@main /root]# vi /root/bin/iptables.sh

 

 


  1 #! /bin/bash
  2 iptables -F
  3
  4 # Local ACCPET
  5 iptables -A INPUT -i lo -j ACCEPT
  6 iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  7 iptables -A INPUT -m state --state ESTABLISHED,RELATED -p all -j ACCEPT
  8
  9 # DNS ACCPET
 10 iptables -A INPUT -p udp --dport 53 -j ACCEPT
 11
 12 # ICMP ACCPET
 13 iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
 14
 15 # TELNET ACCPET
 16 iptables -A INPUT -s 172.20.1.101 -p tcp --dport 23 -j ACCEPT
 17
 18 # HTTP ACCPET
 19 iptables -A INPUT -d 172.20.1.1 -p tcp --dport 80 -j ACCEPT
 20 iptables -A INPUT -d 172.20.1.1 -p tcp --dport 443 -j ACCEPT
 21
 22 # E-Mail ACCEPT
 23 iptables -A INPUT -p tcp --dport 25 -j ACCEPT
 24 iptables -A INPUT -p tcp --dport 110 -j ACCEPT
 25 iptables -A INPUT -p tcp --dport 143 -j ACCEPT
 26
 27 # ALL DROP
 28 iptables -P INPUT DROP
 

: wq!
 


 

 

[root@main /root]# ls /root/bin
iptables.sh


 

 

[root@main /root]# chmod 755 /root/bin/iptables.sh
[root@main /root]# /root/bin/iptables.sh


 

 

[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere            anywhere            tcp dpt:ssh
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     udp  --  anywhere           anywhere            udp dpt:domain
ACCEPT     icmp --  anywhere           anywhere            icmp echo-request
ACCEPT     tcp  --  clone1                anywhere            tcp dpt:telnet
ACCEPT     tcp  --  anywhere            test.com              tcp dpt:http
ACCEPT     tcp  --  anywhere             test.com             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:smtp
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:pop3
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:imap

 

 

 - iptables 서비스 재시작 실시

 

[root@main /root]# service iptables restart
iptables: 체인을 ACCEPT 규칙으로 설정 중:  filter          [  OK  ]
iptables: 방화벽 규칙을 지웁니다:                          [  OK  ]
iptables: 모듈을 언로드하는 중:                            [  OK  ]
iptables: 방화벽 규칙 적용 중:                             [  OK  ]


 


[root@main /root]# iptables -L INPUT
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh

 

 

 ~ 중간 생략 ~

 

  8 # connection is considered secure and plaintext authentication is allowed.
  9 disable_plaintext_auth = no
 10
 

: wq!
 

 

 

 

 - 'dovecot' 서비스를 재시작한다.

 

[root@main /root]# service dovecot start
Dovecot Imap (을)를 시작 중:


[root@main /root]# service dovecot restart
Dovecot Imap 를 정지 중:                                   [  OK  ]
Dovecot Imap (을)를 시작 중:                               [  OK  ]

 

[root@main /root]# chkconfig dovecot on

 

 

 

 

 

4. 테스트

 

 - 이-메일 계정으로 사용할 사용자 계정을 메일 그룹으로 변경한다.

 

[root@main /root]# usermod -G mail user1

[root@main /root]# usermod -G mail user2

 

 

 

-  main에서 에볼루션을 실행하여 user1 계정을 등록하도록 한다.

 

 

밑에 편지 봉투 아이콘 클릭

 

 

 

 

앞으로(F) 클릭

 

 

 

 

앞으로(F) 클릭

 

 

 

 

user1에 대한 필요 정보 및 추가 정보 입력 -> 앞으로(F) 클릭

 

 

 

 

서버 종류 : POP 선택 -> 설정 내용 입력 -> 앞으로(F)

 

 

 

 

앞으로(F) 클릭

 

 

 

 

서버 종류 : SMTP 선택 -> 서버 설정 내용 입력 -> 앞으로(F) 클릭

 

 

 

 

이름(N) 내용 입력 -> 앞으로(F) 클릭

 

 

 

 

적용(A) 클릭

 

 

 

 

이러한 방식으로 clone1에서 user2 계정을 등록하도록 한다.

 

 

 

 

 

main 에볼루션 -> '새로 만들기' 클릭

 

 

 

 

받는 사람 : user2@test.com -> 제목 및 내용 입력 -> '보내기' 클릭

 


 

 

clone1 에볼루션 -> '보내고 받기' 클릭 -> 수신 메일 및 내용 확인