13 ธันวาคม 2568

Traefik dnsChallenge with Clouflare DNS

 .env
LETSENCRYPT_TOKEN=<your_cloudflare_api_token>

docker-compose.yml
- TRAEFIK_CERTIFICATESRESOLVERS_CLOUDFLARE_ACME_DNSCHALLENGE_CLOUDFLARE_DNS_API_TOKEN=${LETSENCRYPT_TOKEN}

traefik_config.yml
certificatesResolvers:
  cloudflare:
    acme:
      dnsChallenge:
        provider: "cloudflare"
      email: "<your_email>"
      storage: "/letsencrypt/cloudflare.json"

ref: https://go-acme.github.io/lego/dns/cloudflare/

04 ธันวาคม 2568

SSL script with Certbot and RFC2136

 #!/bin/bash

# Certificate management script with Certbot and RFC2136

DOMAIN='*.example.com'  # Replace with your domain
EMAIL='your-email@example.com' # Replace with your email for notifications
DNS_SERVER='10.0.0.1' # Replace with your DNS server IP
KEY_NAME='your-key-name'  # Must match the key name on your DNS server
KEY_SECRET='your-base64-secret'  # Base64 encoded secret
KEY_ALGORITHM='HMAC-SHA512'  # or HMAC-MD5, HMAC-SHA1, HMAC-SHA256, HMAC-SHA384
PROPAGATION_SECONDS=20  # Time to wait for DNS propagation

# Create temporary rfc2136 credentials file on host
TMP_CREDS=$(mktemp)
cat > "$TMP_CREDS" <<EOF
dns_rfc2136_server = $DNS_SERVER
dns_rfc2136_name = $KEY_NAME
dns_rfc2136_secret = $KEY_SECRET
dns_rfc2136_algorithm = $KEY_ALGORITHM
EOF
chmod 600 "$TMP_CREDS"

echo "Created temporary credentials file: $TMP_CREDS"
echo "Issuing new certificate for $DOMAIN with Certbot (RFC2136)..."

docker run --rm -it \
    -v ./letsencrypt:/etc/letsencrypt \
    -v "$TMP_CREDS:/tmp/rfc2136.ini:ro" \
    certbot/dns-rfc2136 \
    certonly \
    --dns-rfc2136 \
    --dns-rfc2136-credentials /tmp/rfc2136.ini \
    --dns-rfc2136-propagation-seconds $PROPAGATION_SECONDS \
    --email "$EMAIL" \
    --agree-tos \
    --non-interactive \
    -d "$DOMAIN"

# Clean up temporary file
rm -f "$TMP_CREDS"
echo "Cleaned up temporary credentials file"
echo "Done!"

SSL script with acme.sh and RFC2136

 #!/bin/bash

# Certificate management script with acme.sh and RFC2136

NSUPDATE_SERVER='10.0.0.1' # Replace with your DNS server IP
NSUPDATE_ZONE='example.com' # Replace with your DNS zone
DOMAIN='*.example.com'  # Replace with your domain
KEY_NAME='your-key-name' # Must match the key name on your DNS server
KEY_SECRET='your-base64-secret' # Base64 encoded secret
KEY_ALGORITHM='hmac-sha512' # or hmac-md5, hmac-sha1, hmac-sha256, hmac-sha384

# Create nsupdate key content
NSUPDATE_KEY_CONTENT="key \"$KEY_NAME\" {
    algorithm $KEY_ALGORITHM;
    secret \"$KEY_SECRET\";
};"

echo "Issuing new certificate for $DOMAIN with acme.sh (RFC2136)..."
docker run --rm -it \
    -e NSUPDATE_SERVER="$NSUPDATE_SERVER" \
    -e NSUPDATE_KEY='/tmp/nsupdate.key' \
    -e NSUPDATE_ZONE="$NSUPDATE_ZONE" \
    -v ./acme.sh:/acme.sh \
    neilpang/acme.sh \
    sh -c "echo '$NSUPDATE_KEY_CONTENT' > /tmp/nsupdate.key && acme.sh --issue --server letsencrypt -k ec-256 --dns dns_nsupdate -d $DOMAIN"

echo "Done!"

02 ธันวาคม 2568

Block Adguard Home admin but allow DOH

 location /dns-query {
    proxy_pass https://10.0.0.103/dns-query;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location / {
    return 404;
}

20 มีนาคม 2568

Mikrotik container : ZeroTier network controller user interface

No public IP address is required; an internet connection alone is sufficient.

/container mounts
add dst=/opt/key-networks/ztncui/etc name=ztncui src=/ztncui
add dst=/var/lib/zerotier-one name=zerotier-one src=/zerotier-one

/container envs
add key=NODE_ENV name=zerotier value=production
add key=HTTPS_PORT name=zerotier value=3443
add key=ZTNCUI_PASSWD name=zerotier value=password

/container
add comment=zeerotier envlist=zerotier interface=veth-zerotier logging=yes mounts=ztncui,zerotier-one start-on-boot=yes workdir=/

WARNING: IF YOU DO NOT SET PASSWORD, YOU HAVE TO USE container shell <CONTAINER ID>, and then cat /var/log/docker-ztncui.log to get your random password. This is gatekeeper.

ref
- https://gist.github.com/dnburgess/b839c2230890068c30bb5ed5ee2d22ba
- https://github.com/key-networks/ztncui-aio

05 กุมภาพันธ์ 2568

Mikrotk hEX refresh (E50UG) run cloudflared container

For devices with EN7562CT CPU, only arm32v5 container images are supported.
 
 
/disk
add slot=tmpfs tmpfs-max-size=160M type=tmpfs

/container config
set registry-url=https://registry-1.docker.io tmpdir=tmpfs

/file
add name=/opt-cf/cloudflared.sh type=file contents="/bin/apt update\n\
/bin/apt -y install wget\n\
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm -O /usr/local/bin/cloudflared\n\
chmod +x /usr/local/bin/cloudflared\n\
/usr/local/bin/cloudflared tunnel --no-autoupdate run --token XXX"

/container mounts
add dst=/opt-cf/cloudflared.sh name=opt-cf src=/opt-cf/cloudflared.sh read-only=yes

/container
add remote-image=arm32v5/debian:13-slim interface=cf-tunnel mounts=opt-cf root-dir=tmpfs logging=yes cmd="bash /opt-cf/cloudflared.sh"

12 ธันวาคม 2567

openssl generate CSR

rsa:2048

openssl req -new -newkey rsa:2048 -nodes \
  -keyout domain.tld.key \
  -out domain.tld.csr \
  -subj "/C=TH/ST=Bangkok/O=Organization/OU=IT/CN=www.domain.tld"
 

rsa:2048 with SAN

openssl req -new -newkey rsa:2048 -nodes \
  -keyout domain.tld.key \
  -out domain.tld.csr \
  -subj "/C=TH/ST=Bangkok/O=Organization/OU=IT/CN=www.domain.tld"  \
  -addext "subjectAltName = DNS:www.domain2.tld,DNS:www.domain3.tld"
 

P-256 (ECC)

openssl req -new -newkey ec:<(openssl ecparam -name prime256v1) -nodes \
  -keyout domain.tld.key \
  -out domain.tld.csr \
  -subj "/C=TH/ST=Bangkok/O=Organization/OU=IT/CN=www.domain.tld
 

P-256 (ECC) with SAN

openssl req -new -newkey ec:<(openssl ecparam -name prime256v1) -nodes \
  -keyout domain.tld.key \
  -out domain.tld.csr \
  -subj "/C=TH/ST=Bangkok/O=Organization/OU=IT/CN=www.domain.tld" \
  -addext "subjectAltName = DNS:www.domain2.tld,DNS:www.domain3.tld"
 
 
C = Country Name (2 letter code)
ST = State or Province Name
O = Organization Name
OU = Organizational Unit
CN = Common Name