DNS 管理基本上都是大同小異啦,可是namecheap 免費賬戶不提供 API ,應該說要使用namecheap 提供的API ,需要滿足以下的條件
1
2
3
4
5
6
7
I want to enable API for my account. Are there any specific requirements?
We have certain requirements for activation to prevent system abuse. In order to have API enabled for your account, you should meet one of the following requirements:
- have at least 20 domains under your account;
- have at least $50 on your account balance;
- have at least $50 spent within the last 2 years.
#/etc/acme-dns/config.cfg[general]# DNS interface# 本來預設是只有 :53 在某些VPS 上會出錯,所以改成 0.0.0.0:53listen="0.0.0.0:53"protocol="udp"# domain name to serve the requests off of# 不是要設定的 domain,而是這臺機器要負責的sub domain# 總之就是輸入 acme 再加上原本的domain# 不想用 acme 當然也可以domain="acme.abc.com"# zone name server# ns1 再加上原本的 domain# 一樣,不想用ns1 也可以,後面記得作對應的修改nsname="ns1.abc.com"# admin email address, where @ is substituted with .# 管理者email , admin + 原本的 domainnsadmin="admin.abc.com"# predefined records served in addition to the TXT# # 前面兩筆 A 記錄對應上面的 domain , nsname# 後面則是這臺機器的 WAN IP# 第三筆 是NS 記錄# 這三筆記錄等一下要新增到namecheap 的DNS records=["acme.abc.com. A 11.22.33.44",
"ns1.acme.abc.com. A 11.22.33.44",
"acme.abc.com. NS ns1.abc.com.",
]debug=false[database]engine="sqlite3"connection="/var/lib/acme-dns/acme-dns.db"### 要記一下port ,等等會用到[api]api_domain=""ip="127.0.0.1"disable_registration=falseautocert_port="80"port="9000"tls="none"corsorigins=["*"]use_header=falseheader_name="X-Forwarded-For"[logconfig]loglevel="debug"logtype="stdout"logformat="text"
編輯完後,存檔離開。
新增 acme-dns.service 的systemd config
1
sudo vim /etc/systemd/system/acme-dns.service
內容如下
1
2
3
4
5
6
7
8
9
10
11
# /etc/systemd/system/acme-dns.service[Unit]Description=ACMD DNS
After=network.target
[Service]ExecStart=/usr/local/bin/acme-dns
Restart=on-failure
[Install]WantedBy=multi-user.target
# 第一個ACME_DNS_API_BASE是剛剛設定acme-dns API port# 然後 ACME_DNS_STORAGE_PATH 是lego存放賬戶資料的地方# 後面就是lego 的指令ACME_DNS_API_BASE=http://localhost:9000 ACME_DNS_STORAGE_PATH=/home/minion/.lego-acme-dns-accounts.json lego --email changch@abc.com --dns acme-dns --domains *.abc.com run
執行完成後,會在目錄底下產生一個叫 .lego 的目錄,用來存放憑證檔案
1
2
3
4
5
6
7
8
9
2021-08-26 11:55:16 [minion@hqs058 ~]$ ls -la .lego/certificates/
total 28drwx------ 2 minion sudo 4096 Aug 26 09:35 .
drwx------ 4 minion sudo 4096 Aug 26 09:33 ..
-rw------- 1 minion sudo 5325 Aug 26 09:35 _.abc.com.crt
-rw------- 1 minion sudo 3751 Aug 26 09:35 _.abc.com.issuer.crt
-rw------- 1 minion sudo 238 Aug 26 09:35 _.abc.com.json
-rw------- 1 minion sudo 227 Aug 26 09:35 _.abc.com.key
2021-08-26 11:58:22 [minion@hqs058 ~]$
沒錯,就這麼簡單!!
甚至於我要撤銷這些憑證也很簡單!!!
把最後面的 run 改成 revoke 就可以了!
1
2
3
4
ACME_DNS_API_BASE=http://localhost:9000 ACME_DNS_STORAGE_PATH=/home/minion/.lego-acme-dns-accounts.json lego --email changch@abc.com --dns acme-dns --domains *.abc.com revoke
2021/08/26 11:59:13 Trying to revoke certificate for domain *.abc.com
2021/08/26 11:59:14 Certificate was revoked.
2021/08/26 11:59:14 Certificate was archived for domain: *.abc.com
再來跑一次申請新憑證測試看看
1
2
3
4
5
6
ACME_DNS_API_BASE=http://localhost:9000 ACME_DNS_STORAGE_PATH=/home/minion/.lego-acme-dns-accounts.json lego --email changch@abc.com --dns acme-dns --domains *.abc.com run
2021/08/26 12:00:51 [INFO][*.abc.com] acme: Obtaining bundled SAN certificate
2021/08/26 12:00:52 [INFO][*.abc.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz-v3/25150773810
2021/08/26 12:00:52 [INFO][*.abc.com] acme: authorization already valid; skipping challenge
2021/08/26 12:00:52 [INFO][*.abc.com] acme: Validations succeeded; requesting certificates
2021/08/26 12:00:53 [INFO][*.abc.com] Server responded with a certificate.
同樣地,會產生新的ssl 憑證
1
2
3
4
5
6
7
8
9
2021-08-26 12:00:53 [minion@hqs058 ~]$ ls -la .lego/certificates/
total 28drwx------ 2 minion sudo 4096 Aug 26 12:00 .
drwx------ 5 minion sudo 4096 Aug 26 11:59 ..
-rw------- 1 minion sudo 5325 Aug 26 12:00 _.abc.com.crt
-rw------- 1 minion sudo 3751 Aug 26 12:00 _.abc.com.issuer.crt
-rw------- 1 minion sudo 238 Aug 26 12:00 _.abc.com.json
-rw------- 1 minion sudo 227 Aug 26 12:00 _.abc.com.key
2021-08-26 12:02:37 [minion@hqs058 ~]$
超方便的啊!!!!
後面要更新就把指令最後的 run 改成 renew
1
2
ACME_DNS_API_BASE=http://localhost:9000 ACME_DNS_STORAGE_PATH=/home/minion/.lego-acme-dns-accounts.json lego --email changch@abc.com --dns acme-dns --domains *.abc.com renew
2021/08/26 12:04:00 [*.abc.com] The certificate expires in 89 days, the number of days defined to perform the renewal is 30: no renewal.