Skip to content

Blog

Cloudflare DDNS with ShellScripts


tags: - Shellcategories: - Linux - Networkdate:created: 2023-04-08# updated: 2024-01-19—

1. IntroductionWith the popularity of IPv6 and the unavailability of IPv4 on the public network, the demand for using IPv6 to access external networks has gradually increased. This article uses Cloudflare DNS API to implement IPv6 DDNS.

Section titled “1. IntroductionWith the popularity of IPv6 and the unavailability of IPv4 on the public network, the demand for using IPv6 to access external networks has gradually increased. This article uses Cloudflare DNS API to implement IPv6 DDNS.”

2. Environment Requirements- OS: Linux with SHELL(sh), Other Unix maybe.- HostName: example.com- HostName for DDNS: ddns.example.com

Section titled “2. Environment Requirements- OS: Linux with SHELL(sh), Other Unix maybe.- HostName: example.com- HostName for DDNS: ddns.example.com”

(1) Obtain theZone IDandAPI Keyof the domain nameThe Zone ID can be obtained directly from the API column at the bottom right of the domain name control panel.

Section titled “(1) Obtain theZone IDandAPI Keyof the domain nameThe Zone ID can be obtained directly from the API column at the bottom right of the domain name control panel.”

To obtain the API Key, you need to click “Get your API key” below the column, then enter the password and verification code to confirm. In fact, you can also create a new API Key yourself instead of using the global API Key.

(2) Add the AAAA record of the subdomain nameIn the “DNS” tab of the domain name panel, add an AAAA record in DNS Records, takingddns.example.comas an example:- Name: “ddns”- IPv6 address: “::1”- TTL: NULL- CDN: None

Section titled “(2) Add the AAAA record of the subdomain nameIn the “DNS” tab of the domain name panel, add an AAAA record in DNS Records, takingddns.example.comas an example:- Name: “ddns”- IPv6 address: “::1”- TTL: NULL- CDN: None”

(3) Get the RecordID of the AAAA recordddns.example.comExecute on the command line:

Section titled “(3) Get the RecordID of the AAAA recordddns.example.comExecute on the command line:”
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records?\
type=AAAA&name=DDNS_HOSTNAME&content=127.0.0.1&\
page=1&per_page=100&order=type&direction=desc&match=any" \
-H "X-Auth-Email: CF_EMAIL" \
-H "X-Auth-Key: CF_API_KEY" \
-H "Content-Type: application/json" \
| python -m json.tool
  • ZONE_ID isZone IDobtained in the first step- DDNS_HOSTNAME is the domain name for setting the AAAA record in the second step- CF_EMAIL is the registered email address of the Cloudflare account- CF_API_KEY isAPI KEYobtained in the first step After successful execution, a piece of output in JSON format will be returned. Find the"id"corresponding to the domain nameddns.example.cominresult

A useful Cloudflare Shell API is available on my gitlab: [gitlab.dashdreams.com], all based on scripts above.

(5)Run the scriptAdd execution permissions to the scriptsudo chmod +x ddns.sh

Section titled “(5)Run the scriptAdd execution permissions to the scriptsudo chmod +x ddns.sh”

Run scriptsudo ./ddns.sh

[2].Execute-Scripts-on-Period-with-Systemd [3].Shell string interception [4].Linux-A brief analysis of text processing commands [gitlab.dashdreams.com]:https://gitlab.dashdreams.com:8443/Haoran.Qi/RaspberryPi

Execute Scripts on Period with SystemdThis tutorial aims to implement scheduled execution tasks through`Timer`that comes with`Systemd`


tags: - Systemd - Shellcategories: - Linuxdate:created: 2023-08-20# updated: 2024-01-19—

Execute Scripts on Period with SystemdThis tutorial aims to implement scheduled execution tasks throughTimerthat comes withSystemd

Section titled “Execute Scripts on Period with SystemdThis tutorial aims to implement scheduled execution tasks throughTimerthat comes withSystemd”

This article takesgit pullthat implements timing as an example to explain the timer ofSystemd

1. Create agit pullScriptThe main purpose of this script is to enter the specified git path and execute thegit pullinstruction> You need to make sure that there is a git repository that has been cloned locally in this path.

Section titled “1. Create agit pullScriptThe main purpose of this script is to enter the specified git path and execute thegit pullinstruction> You need to make sure that there is a git repository that has been cloned locally in this path.”

(1). The content ofvim gitpull.shis as follows:

Section titled “(1). The content ofvim gitpull.shis as follows:”
#!/bin/sh
cd ${pwd_of_git_repo_path}
git pull

${pwd_of_git_repo_path} represents the folder of the git repository

(2). After editing, save and exit:wq, and add running permissions to the script:

Section titled “(2). After editing, save and exit:wq, and add running permissions to the script:”
sudo chmod +x gitpull.sh

Run./gitpull.shon the command line. When the command line displays the same output as the commandgit pullwhen running normally, it means that the script is normal.

(1). Create a file namedgitpull.servicein the/etc/systemd/system/or/usr/lib/systemd/system/directory with the following content:

Section titled “(1). Create a file namedgitpull.servicein the/etc/systemd/system/or/usr/lib/systemd/system/directory with the following content:”
[Unit]
Description=gitpull service
[Service]
User=${USER}
Group=${GROUP}
ExecStart=/bin/bash ${pwd_of_scripts}/gitpull.sh
[Install]
WantedBy=multi-user.target

${pwd_of_scripts} represents the folder where the script created in the previous step is located> ${USER} represents the user who executes the script, ${GROUP} represents the group to which the user belongs

Reload and run gitpull.service

sudo systemctl daemon-reload
sudo systemctl start gitpull.service

Check the output log ofSystemdto determine whether the service is running normally and whether the output is the same as that of direct git pull

sudo systemctl status gitpull.service

(1). Create a timer with the following content:

Section titled “(1). Create a timer with the following content:”
[Unit]
Description=run gitpull.sh every 1hour
[Timer]
OnUnitActiveSec=1h
Unit=gitpull.service
[Install]
WantedBy=multi-user.target

The name ofTimerneeds to be consistent with the name ofService> OnUnitActiveSecrepresents the interval at which the run timer runs> Oncalnedarmeans running at a specific time> Unitrepresents the service that needs to be run

  • Oncalnedar* *-*-* *:*:* - *- To signify the day of the week eg:- Sat,Thu,Mon - *-*-* - To signify the calendar date. Which means it breaks down to - year-month-date. - 2021-10-15 is the 15th of October - *-10-15 means every year at 15th October - *-01-01 means every new year. - *:*:*is to signify the time component of the calnedar event. So it is - hour:minute:second
sudo systemctl daemon-reload
sudo systemctl start gitpull.timer

Check the operating status and output of gitpull.service and gitpull.timer

sudo systemctl status gitpull.service
sudo systemctl status gitpull.timer
sudo systemctl enable gitpull.service
sudo systemctl enable gitpull.timer

[2]. https://silentlad.com/systemd-timers-oncalendar-(cron)-format-explained

[3]. Systemd-a first exploration [4]. Cloudflare-DDNS-with-ShellScripts [5]. Auto-Archive-Files-with-ShellScripts

Linux Auto PAC


tags: - PACcategories: - Linuxdate:created: 2020-08-18# updated: 2024-01-19—

1. Install genpacIf pip is not installed, install pip firstsudo apt-get install python-pip``pip install genpac

Section titled “1. Install genpacIf pip is not installed, install pip firstsudo apt-get install python-pip``pip install genpac”

mkdir ~/shadowsocks cd shadowsocks genpac –proxy=“SOCKS5 127.0.0.1:1080” –gfwlist-proxy=“SOCKS5 127.0.0.1:1080” -o autoproxy.pac –gfwlist-url=“https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt”

- 1080 represents the port number of the proxy
## 3. Enter the following command on the command line to check whether the agent is running normally```
curl -so /dev/null -w "%{http_code}" google.com -x socks5://127.0.0.1:1080
  • socks5indicates the proxy protocol used, which can be replaced by other protocols such ashttp- 10080is the port number of the proxy, corresponding to the Input port of the proxy service

4. Configure system network Proxy### GUI interfaceOpen the following path[system] settings -> network -> network proxySelect the proxy mode as automatic, and fill in the configuration url as

Section titled “4. Configure system network Proxy### GUI interfaceOpen the following path[system] settings -> network -> network proxySelect the proxy mode as automatic, and fill in the configuration url as”

file:///PATH_TO_PAC/autoproxy.pac

  • Fill in the path of the pac file according to the actual situation

[2]. Check whether the agent is running normally

Manage Podman Container With Systemd


tags: - Podmancategories: - Containerdate:created: 2023-05-27# updated: 2024-01-19—

1. Problem IntroductionPodman is different from Docker in that it does not require the docker daemon to control the running of the container in terms of architecture, so the restart of the container needs to be taken over by systemd.

Section titled “1. Problem IntroductionPodman is different from Docker in that it does not require the docker daemon to control the running of the container in terms of architecture, so the restart of the container needs to be taken over by systemd.”
podman generate systemd -t 30 -n --new -f web
  • -t: timeout period- -n: indicates using the container name instead of the container id- -f: indicates generating service files- –new: Delete the old container and start a new container every time it is started

3. Manage Pod with Systemd### (1). Create a Pod```

Section titled “3. Manage Pod with Systemd### (1). Create a Pod```”

podman pod create –name POD_NAME

### (2). Create Container in Pod```
podman container run --pod POD_NAME --name CONTAINER_NAME1
podman container run --pod POD_NAME --name CONTAINER_NAME2

(3). Generate systemd service files for Pod and Containers inside```

Section titled “(3). Generate systemd service files for Pod and Containers inside```”

podman generate systemd -f –new –name POD_NAME

- -f: indicates generating service files- --new: Delete the old container and start a new container every time it is started- POD_NAME: pod name
## 4. Config Systemd
### (1). Move service file to`/usr/lib/systemd/system`### (2). Restore SELinux Label with command below```
restorecon /usr/lib/systemd/system/container-***.service

systemctl daemon-reload

### (4). Set Service Enabled```
systemctl enable container-***.service

[2]. https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/9/html/building_running_and_managing_containers/assembly_porting-containers-to-systemd-using-podman_building-running-and-managing-containers#doc-wrapper

[3]. https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/9/html/building_running_and_managing_containers/proc_auto-starting-pods-using-systemd_assembly_porting-containers-to-systemd-using-podman

[4]. Systemd-a first exploration

Notes on Podman Network

This is a note on some issues relating to podman network and firewalld on RHEL.

  • RHEL 9.4
  • Podman 4.9.4-rhel
–network –net -p firewall status
- [x] [x] Allowed
bridge [x] [x] Blocked
host - - Blocked

As showed in table above, if using podman with --net -p parameters only, firewalld will not block the access on this port.

However, with --network bridge configured, and paramters above configured, the firewalld will block this access.

And as showed, firewalld will block all access on configuring --network host.

On ports mapping, spefic ip address like 127.0.0.1 on host port.

[1]. Linux-Firewall-初探

[2]. Netstat-常用参数