서버 설정 · 5 min read · Oct 13, 2025

완벽한 스팸스네이크 - 우분투 제오스 12.04 LTS 정밀 판골린

완벽한 스팸스네이크 - 우분투 제오스 12.04 LTS 정밀 판골린

작성자: 로키
버전: 5

Postfix w/Bayesian Filtering, Postscreen, Postfix Recipient Callout (Relay Recipients via look-ahead Optional), Nginx/Uwsgi, Mysql, Dnsmasq, MailScanner (Spamassassin, ClamAV, Pyzor, Razor, DCC-Client), Baruwa, SPF Checks, FuzzyOcr, Sanesecurity Signatures, Greyfix, KAM, Scamnailer, FireHOL (Iptables Firewall), Relay Recipients Script (Optional), Webmin (Optional), Outgoing Disclaimer with alterMIME (Optional)

이 튜토리얼은 게이트웨이 모드에서 스팸 필터로서 우분투 제오스 기반 서버를 설정하는 방법을 보여줍니다. 마지막에는 깨끗한 이메일을 MTA로 릴레이하는 스팸스네이크 게이트웨이를 갖게 됩니다. 또한 수신 대기열을 보고, 스팸스네이크를 훈련시키고, Baruwa를 통해 몇 가지 더 고급 작업을 수행할 수 있습니다.

이 방법이 저에게 작동하는 것처럼 여러분에게도 작동할 것이라고 보장할 수는 없습니다.

다음 소프트웨어를 사용할 것입니다:
• 웹 서버: Nginx v1.1.19/Uwsgi v1.0.3
• 데이터베이스 서버: MySQL v5.5.28
• 메일 서버: Postfix v2.9.3
• 캐싱 DNS 서버: Dnsmasq 2.59
• 필터: MailScanner v4.84.5-3
• 프론트엔드: Baruwa v1.1.2-4sn

HowToForge의 사람들과 MailScanner, Baruwa, Clamav, Nginx/Uwsgi, Mysql, Postfix, Spamassassin, Razor/Pyzor/DCC 및 Firehol의 개발자들에게 감사드립니다.

기본 설치

  1. 최소 vm 옵션 설치
    호스트 이름을 server1로 설정
  2. 기본 안내 파티션 방법
  3. 사용자 설정:
    u: administrator
    p: password
    암호화 없음
  4. 자동 업데이트 없음
  5. OpenSSH 설치

설치 후

1. 루트 권한 얻기

루트 비밀번호를 설정하여 루트 로그인을 활성화합니다. 이제 루트로 직접 로그인할 수 있습니다:

sudo passwd root

2. 네트워크 구성

우분투 설치 프로그램이 DHCP를 통해 네트워크 설정을 가져오도록 시스템을 구성했기 때문에, 서버는 정적 IP 주소를 가져야 하므로 이제 이를 변경해야 합니다. /etc/network/interfaces를 편집하고 필요에 맞게 조정합니다(이 예제 설정에서는 IP 주소 192.168.0.100을 사용할 것입니다):

vi /etc/network/interfaces

다음과 같이 보이도록 만듭니다:

# 이 파일은 시스템에서 사용 가능한 네트워크 인터페이스와 이를 활성화하는 방법을 설명합니다.
# 더 많은 정보는 interfaces(5)를 참조하십시오.
# 루프백 네트워크 인터페이스
auto lo
iface lo inet loopback
# 기본 네트워크 인터페이스
auto eth0
iface eth0 inet static
        address 192.168.0.100
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1
        dns-nameservers 192.168.0.1

그런 다음 네트워크를 재시작합니다:

/etc/init.d/networking restart
vi /etc/hosts

다음과 같이 보이도록 만듭니다:

127.0.0.1       localhost.localdomain   localhost
192.168.0.100   server1.example.com     server1
# 다음 줄은 IPv6 호스트에 대해 바람직합니다.
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

이제 실행합니다:

echo server1.example.com > /etc/hostname  
reboot now

그 후, 실행합니다:

hostname  
hostname -f

둘 다 이제 server1.example.com을 표시해야 합니다.

3. 기본 셸 변경

/bin/sh는 /bin/dash에 대한 심볼릭 링크이지만, 우리는 /bin/dash가 아닌 /bin/bash가 필요합니다. 따라서 이렇게 합니다:

dpkg-reconfigure dash

dash를 /bin/sh로 설치하시겠습니까? <– 아니요

나중에 필요할 몇 가지 패키지와 요구 사항을 설치합니다:

apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-raw-zlib-perl libdb4.8-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap openssl perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential telnet wget gawk -y

4. 캐싱 Dnsmasq

apt-get install dnsmasq -y
vi /etc/dnsmasq.conf

Dnsmasq가 로컬호스트에서 수신하도록 설정합니다:

listen-address=127.0.0.1

5. Mysql 설치

apt-get install mysql-client mysql-server libdbd-mysql-perl -y 

MySQL 루트 사용자에 대한 비밀번호를 제공하라는 메시지가 표시됩니다 - 이 비밀번호는 root@localhost와 [email protected] 모두에 유효하므로 나중에 MySQL 루트 비밀번호를 수동으로 지정할 필요가 없습니다:

MySQL “root” 사용자에 대한 새 비밀번호: <– yourrootsqlpassword
MySQL “root” 사용자에 대한 비밀번호를 반복 입력하십시오: <– yourrootsqlpassword

6. Postfix 설치:

apt-get install postfix postfix-mysql postfix-doc procmail -y

두 가지 질문이 표시됩니다. 다음과 같이 대답하십시오:

메일 구성의 일반 유형: –> 인터넷 사이트
시스템 메일 이름: –> server1.example.com

Postfix를 중지합니다:

postfix stop
vi /etc/postfix/master.cf

다음과 같이 보이도록 만듭니다:

pickup    fifo  n       -       -       60      1       pickup
         -o content_filter=
         -o receive_override_options=no_header_body_checks

main.cf 편집:

vi /usr/src/postfix.sh

다음과 같이:

#!/bin/sh
postconf -e "alias_maps = hash:/etc/aliases"
newaliases
postconf -e "myorigin = domain.tld"
postconf -e "myhostname = server1.domain.tld"
postconf -e "mynetworks = 127.0.0.0/8, 192.168.0.0/24"
postconf -e "message_size_limit = 10485760"
postconf -e "local_transport = error:No local mail delivery"
postconf -e "mydestination = "
postconf -e "local_recipient_maps = "
postconf -e "relay_domains = mysql:/etc/postfix/mysql-relay_domains.cf"
postconf -e "relay_recipient_maps = mysql:/etc/postfix/mysql-relay_recipients.cf"
postconf -e "transport_maps = mysql:/etc/postfix/mysql-transports.cf"
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
postconf -e "disable_vrfy_command = yes"
postconf -e "strict_rfc821_envelopes = no"
postconf -e "smtpd_banner = $myhostname ESMTP SpamSnake"
postconf -e "smtpd_delay_reject = yes"
postconf -e "smtpd_recipient_limit = 100"
postconf -e "smtpd_helo_required = yes"
postconf -e "smtpd_client_restrictions = permit_sasl_authenticated, permit_mynetworks, permit"
postconf -e "smtpd_helo_restrictions = permit_sasl_authenticated, permit_mynetworks, permit"
postconf -e "smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_sender, reject_unknown_sender_domain, permit"
postconf -e "smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unknown_recipient_domain, reject_unauth_destination, whitelist_policy, grey_policy, rbl_policy, spf_policy, permit"
postconf -e "smtpd_data_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_pipelining"
postconf -e "smtpd_restriction_classes = spf_policy, grey_policy, whitelist_policy"
postconf -e "spf_policy = check_policy_service unix:private/policy-spf"
postconf –e "policy-spf_time_limit = 3600s"
postconf -e "rbl_policy = reject_rbl_client zen.spamhaus.org, reject_rbl_client bl.spamcop.net"
postconf -e "grey_policy = check_policy_service unix:private/greyfix"
postconf -e "whitelist_policy = check_client_access mysql:/etc/postfix/mysql-global_whitelist.cf, check_sender_access mysql:/etc/postfix/mysql-global_whitelist.cf"
postconf -e "header_checks = regexp:/etc/postfix/header_checks"
touch /etc/postfix/virtual
echo "root [email protected]" >> /etc/postfix/virtual && echo "abuse [email protected]" >> /etc/postfix/virtual && echo "postmaster [email protected]" >> /etc/postfix/virtual
postmap /etc/postfix/virtual
touch /etc/postfix/header_checks
echo "/^Received:/ HOLD" >> /etc/postfix/header_checks
postmap /etc/postfix/header_checks
cat > /etc/postfix/mysql-global_whitelist.cf < /etc/postfix/mysql-relay_domains.cf < /etc/postfix/mysql-relay_recipients.cf < /etc/postfix/mysql-transports.cf <

참고: 이 단계에서는 [email protected], example.com 및 @example.com을 설정에 맞는 실제 값으로 바꾸는 것을 잊지 마십시오.

실행 가능하게 만들고 실행합니다:

chmod +x /usr/src/postfix.sh
./usr/src/postfix.sh

*참고: cf 파일의 사용자/비밀번호는 나중에 Baruwa DB 설정에 사용할 사용자/비밀번호와 동일해야 합니다. 스크립트를 실행하기 전에 빨간색으로 표시된 모든 것을 변경해야 합니다.

Postfix 수신자 호출(선택 사항)

이 기능은 수신자 서버에 쿼리하여 수신자가 존재하는지 확인합니다. 존재하지 않으면 발신 서버에 550 오류로 응답하고 연결을 끊습니다. 사용자가 존재하는 경우 스팸스네이크는 이메일 처리를 계속합니다. 이는 백스캐터를 방지하는 또 다른 방법이지만 비용이 발생합니다. http://www.postfix.org/ADDRESS_VERIFICATION_README.html에서 자세히 알아보십시오. 이 방법이 서버에 부담을 줄 것이라고 판단되면 이 방법을 건너뛰고 스크립트 방법(이 가이드의 후반부에서)을 사용할 수 있습니다.

vi /etc/postfix/main.cf를 열고 다음을 추가합니다:

verify_recipient = reject_unknown_recipient_domain, reject_unverified_recipient  
look_ahead = check_recipient_access hash:/etc/postfix/access  
unverified_recipient_reject_code = 550  
address_verify_map = btree:/var/lib/postfix/verify

이것을 smtpd_restriction_classes에 추가합니다:

verify_recipient, look_ahead

이것을 smptd_recipient_restrictions에 추가합니다:

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, look_ahead, whitelist_policy, grey_policy, rbl_policy, spf_policy, permit

access 파일을 생성합니다:

touch /etc/postfix/access

도메인을 추가합니다:

cat > /etc/postfix/access <#mysql-transports
example.com verify_recipient
example2.com verify_recipient
EOF

*참고: 필터링할 유효한 도메인을 추가해야 합니다.

Postmap합니다:

postmap /etc/postfix/access

Postfix 설치를 최종적으로 확인합니다:

less /etc/postfix/main.cf

파일의 내용을 확인하여 오류가 있는지 확인하고 필요시 수정합니다. Postfix를 시작합니다:

postfix start

Postfix가 응답하는지 확인합니다:

telnet 127.0.0.1 25

다음과 같은 메시지가 표시되어야 합니다:

220 [yourFQDNhere] ESMTP Postfix (Ubuntu)
Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.