Jace Docs

DuckDNS

DuckDNS 활용한 와일드카드 인증서 발급 방법

https://www.duckdns.org/

개요

Cafe24의 기본 도메인으로는 DNS 설정 권한이 없어 인증서 발급이 막혔으니, DuckDNS를 활용해 우회하는 방법을 알려드릴게요.

DuckDNS는 단순한 DDNS를 넘어 TXT 레코드(API) 설정을 지원하기 때문에, Let's Encrypt의 와일드카드 인증서(*.duckdns.org) 발급이 가능합니다.


DuckDNS & Certbot


1. DuckDNS 도메인 생성 (웹)

  1. DuckDNS 홈페이지에 접속해 소셜 로그인(Google 등)을 합니다.
  2. 메인 화면의 sub domain 칸에 원하는 이름을 넣고 **[add domain]**을 클릭합니다.
    • 예: my-gnbiz.duckdns.org
  3. 상단에 표시된 token 값을 따로 복사해둡니다. (인증서 발급 시 필요)
  4. current ip 칸에 현재 서버의 공인 IP가 맞는지 확인하고, 다르면 수정 후 **[update ip]**를 누릅니다.

2. 와일드카드 인증서 발급하기 (서버 터미널)

DuckDNS는 TXT 레코드를 웹 화면이 아니라 URL(API) 호출로 등록해야 합니다. 수동으로 하는 방법이 가장 확실합니다.

Step 1: Certbot 실행

터미널에서 아래 명령어를 입력합니다. (-d 옵션에 내 도메인과 와일드카드 도메인을 모두 넣습니다.)

sudo certbot certonly --manual -d "본인도메인.duckdns.org" -d "*.본인도메인.duckdns.org" --preferred-challenges dns

Step 2: TXT 레코드 배포 (핵심)

명령어를 실행하면 중간에 아래와 같은 안내가 뜹니다.

Please deploy a DNS TXT record under the name: _acme-challenge.본인도메인.duckdns.org with the following value: 가나다라마바사_12345 (인증값)

이 상태에서 Enter를 누르지 말고, 새 브라우저 창을 열어 아래 주소로 접속합니다.

https://www.duckdns.org/update?domains=본인도메인&token=내토큰&txt=인증값
  • domains: duckdns.org를 뺀 앞부분 이름만 입력
  • token: 아까 복사한 토큰 값
  • txt: Certbot이 화면에 보여준 긴 인증 문자열

화면에 OK라고 나오면 성공입니다. KO가 떴다면 요청이 거부(Rejected) 된 것입니다.

Step 3: 확인 및 완료

약 1분 정도 기다린 후 터미널에서 Enter를 누릅니다. 성공하면 /etc/letsencrypt/live/ 경로에 인증서가 저장됩니다.


3. Nginx 설정 변경

이제 기존에 cafe24.com으로 설정되어 있던 Nginx 설정 파일들을 DuckDNS 주소로 바꿔줘야 합니다.

server {
    listen 443 ssl;
    server_name docs.본인도메인.duckdns.org; # 서브도메인 설정 가능

    ssl_certificate /etc/letsencrypt/live/본인도메인.duckdns.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/본인도메인.duckdns.org/privkey.pem;

    # ... 나머지 프록시 설정
}

# search 서브도메인 (같은 인증서 사용 가능!)
server {
    listen 443 ssl;
    server_name search.yourname.duckdns.org;
    ssl_certificate /etc/letsencrypt/live/yourname.duckdns.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourname.duckdns.org/privkey.pem;
}

 sudo certbot certonly --manual -d "*.gnbiz.duckdns.org" --preferred-challenges dns
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for *.gnbiz.duckdns.org

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.gnbiz.duckdns.org.

with the following value:

jTFsesSEAe10hMVTE5v-7i4TC4R9BZb0PPatHkOeZ0U

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.gnbiz.duckdns.org.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/gnbiz.duckdns.org/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/gnbiz.duckdns.org/privkey.pem
This certificate expires on 2026-06-28.
These files will be updated when the certificate renews.

NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

자동 갱신

외부 플러그인을 설치하기 어려운 환경이라면, DuckDNS API를 직접 호출하는 가벼운 쉘 스크립트를 만들어 Certbot의 --manual-auth-hook에 연결하는 것이 가장 깔끔한 방법입니다.

이 방식은 Certbot이 갱신 시점에 스크립트를 실행하여 TXT 레코드를 자동으로 업데이트하도록 만듭니다.


1. 인증 및 정리 스크립트 작성

먼저 두 개의 스크립트를 만듭니다. (파일 위치는 /usr/local/bin/ 혹은 편한 곳에 두세요.)

A. 인증 스크립트 (duckdns-auth.sh)

Certbot이 제공하는 환경 변수($CERTBOT_VALIDATION)를 DuckDNS API로 쏴주는 역할을 합니다.

#!/bin/bash
# DuckDNS Token (본인의 토큰으로 수정)
TOKEN="your-duckdns-token-here"
DOMAIN="test" # test.duckdns.org 라면 test만 입력

# DuckDNS TXT 레코드 업데이트 API 호출
curl -s "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&txt=$CERTBOT_VALIDATION"

# DNS 전파를 기다리기 위해 잠시 대기 (30~60초 권장)
sleep 60

B. 정리 스크립트 (duckdns-clean.sh)

인증이 끝나면 TXT 레코드를 비워줍니다. (보안 및 깔끔한 관리용)

#!/bin/bash
TOKEN="your-duckdns-token-here"
DOMAIN="test"

# TXT 레코드 초기화
curl -s "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&txt=removed&clear=true"

2. 스크립트 권한 부여

스크립트가 실행 가능하도록 권한을 설정합니다.

chmod +x /path/to/duckdns-auth.sh
chmod +x /path/to/duckdns-clean.sh

3. Certbot으로 인증서 발급 (최초 1회)

이제 수동 입력 대신 스크립트를 인자로 넣어 명령어를 실행합니다. -d 옵션 두 개를 넣어 루트와 와일드카드를 모두 포함시키는 것을 잊지 마세요.

certbot certonly --manual \
  --preferred-challenges dns \
  --manual-auth-hook /path/to/duckdns-auth.sh \
  --manual-cleanup-hook /path/to/duckdns-clean.sh \
  -d "test.duckdns.org" \
  -d "*.test.duckdns.org"

4. 자동 갱신 테스트 및 등록

갱신 테스트

위 방식으로 한 번 성공하고 나면, Certbot 설정 파일에 스크립트 경로가 저장됩니다. 다음 명령어로 시뮬레이션을 해보세요.

certbot renew --dry-run

Crontab 등록

테스트가 성공하면, crontab -e에 아래 내용을 추가하여 하루에 두 번 자동으로 체크하게 만듭니다. (이미 등록되어 있다면 별도로 안 하셔도 됩니다.)

0 0,12 * * * certbot renew --post-hook "systemctl reload nginx"
  • --post-hook은 인증서 갱신이 실제로 성공했을 때만 Nginx를 재시작하여 새 인증서를 적용합니다.

On this page