From 57c63ceb0452afba5018512e30fe16d8f0758a4e Mon Sep 17 00:00:00 2001 From: roc Date: Thu, 7 Mar 2024 12:01:06 +0800 Subject: [PATCH] update at 2024-03-07 12:01:06 --- codeblock/home-network/ddns.yaml | 40 ++++++++++++++++ content/cases/home-network/ddns.md | 66 +++++++++++++++++++++++++++ content/cases/home-network/dnsmasq.md | 2 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 codeblock/home-network/ddns.yaml create mode 100644 content/cases/home-network/ddns.md diff --git a/codeblock/home-network/ddns.yaml b/codeblock/home-network/ddns.yaml new file mode 100644 index 0000000..173a0a9 --- /dev/null +++ b/codeblock/home-network/ddns.yaml @@ -0,0 +1,40 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + app: ddns + name: ddns + namespace: default +spec: + selector: + matchLabels: + app: ddns + template: + metadata: + labels: + app: ddns + spec: + terminationGracePeriodSeconds: 1 + containers: + - image: newfuture/ddns:v2.13.3 + imagePullPolicy: IfNotPresent + name: ddns + securityContext: + privileged: true + volumeMounts: + - mountPath: /config.json + subPath: config.json + name: config + dnsPolicy: Default + hostNetwork: true + restartPolicy: Always + volumes: + - configMap: + name: ddns-config + name: config + updateStrategy: + rollingUpdate: + maxSurge: 0 + maxUnavailable: 1 + type: RollingUpdate + diff --git a/content/cases/home-network/ddns.md b/content/cases/home-network/ddns.md new file mode 100644 index 0000000..b719305 --- /dev/null +++ b/content/cases/home-network/ddns.md @@ -0,0 +1,66 @@ +# DDNS + +## 为什么需要 DDNS 服务 + +如果希望从外面通过 ssh 远程登录家里的路由器,或者通过 VPN 连上家里的内网,就需要知道家里的公网 IP 地址,而公网 IP 地址每次拨号都会变(比如断点或重启路由器就会重新拨号),所以需要一个 DDNS 服务来自动修改 DNS 解析,指向当前家里的公网 IP 地址。 + +## 告知运营商开通固定 IP + +目前我知道的只有电信的宽带支持独占 IP(固定 IP), 即拨号后分配的公网 IP 只有你一家在用,不是多家共享。只有开通了这个固定 IP 功能,你才能从外面通过公网地址连上家里,需要打电话给运营商(电信是 10000),通过人工服务,让客户给开通,理由就说家里有许多智能家居设备(比如摄像头),有从外网连上家里网络的需求。 + + +## DDNS 开源项目 + +本文部署的 DDNS 服务使用这个开源项目:https://github.com/NewFuture/DDNS + +## 目录结构 + +```txt +ddns +├── config +│   └── config.json +├── daemonset.yaml +└── kustomization.yaml +``` + +## 准备 DDNS 配置 + +```json showLineNumbers title="config/config.json" +{ + "$schema": "https://ddns.newfuture.cc/schema/v2.8.json", + "debug": false, + "dns": "dnspod", + "id": "******", + "token": "********************************", + "index4": "shell:ip -4 addr show ppp0 scope global | awk '/inet/{print $2}' | awk -F '/' '{print $1}'", + "ipv4": [ + "home.imroc.cc" + ], + "proxy": null, + "ttl": null +} +``` + +* 我的域名在 DNSPod 管理,所以配置的是 DNSPod 的 id 和 token。 +* 我用的主路由方案,所以获取公网 IP 的方法直接读 `ppp0` 网卡上的公网 IP 地址就行,不需要调外部接口获取。 + +## 准备 daemonset.yaml + + + +## 准备 kustomization.yaml + +```yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - daemonset.yaml + +configMapGenerator: + - files: + - config/config.json + name: ddns-config + +namespace: default +``` diff --git a/content/cases/home-network/dnsmasq.md b/content/cases/home-network/dnsmasq.md index e5a37e3..6698ddc 100644 --- a/content/cases/home-network/dnsmasq.md +++ b/content/cases/home-network/dnsmasq.md @@ -24,7 +24,7 @@ dnsmasq ## 准备 daemonset.yaml - + ## 准备 kustomization.yaml