Google Cloud package update failed
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
Pank's Blog
2023年9月8日 星期五
2023年8月10日 星期四
HAProxy Reverse Proxy with SSL
憑證掛在 Reverse Proxy, 內部走 HTTP
frontend http-in
backend test1.pank.org
backend test2.pank.org
test1.pank.org 及 test2.pank.org 使用同一個 wildcard 憑證,
crt 是 crt+chain+key 放同一個檔
若兩個站的憑證不同,可以用 crt-list 指定多個憑證
例: bind *:443 ssl crt-list /etc/haproxy/crt-list.txt
crt-list.txt 的內容
/etc/haproxy/domain1.com-crt-chain-key.pem
/etc/haproxy/domain2.com-crt-chain-key.pem
有設定 option forwardfor 會帶 X-Forwarded-For 到 backend server
frontend http-in
mode http
bind *:80
bind *:443 ssl crt /etc/haproxy/pank.org-crt-chain-key.pem
use_backend %[req.hdr(Host),lower]
bind *:80
bind *:443 ssl crt /etc/haproxy/pank.org-crt-chain-key.pem
use_backend %[req.hdr(Host),lower]
backend test1.pank.org
balance first
mode http
option forwardfor except 127.0.0.0/8
server web-1 192.168.0.27:80
mode http
option forwardfor except 127.0.0.0/8
server web-1 192.168.0.27:80
backend test2.pank.org
balance first
mode http
option forwardfor except 127.0.0.0/8
server web-2 192.168.0.42:80
mode http
option forwardfor except 127.0.0.0/8
server web-2 192.168.0.42:80
test1.pank.org 及 test2.pank.org 使用同一個 wildcard 憑證,
crt 是 crt+chain+key 放同一個檔
若兩個站的憑證不同,可以用 crt-list 指定多個憑證
例: bind *:443 ssl crt-list /etc/haproxy/crt-list.txt
crt-list.txt 的內容
/etc/haproxy/domain1.com-crt-chain-key.pem
/etc/haproxy/domain2.com-crt-chain-key.pem
有設定 option forwardfor 會帶 X-Forwarded-For 到 backend server
2023年8月9日 星期三
NGINX Reverse Proxy with SSL
憑證掛在 Reverse Proxy, 內部走 HTTP
/etc/nginx/conf.d/test1.conf
server {
若後端有多台,建立多個 conf 即可
有設定 proxy_set_header X-Forwarded-For 會帶 X-Forwarded-For 到 backend server
/etc/nginx/conf.d/test1.conf
server {
listen 443 ssl;
server_name test1.pank.org;
ssl_certificate /etc/nginx/conf.d/pank.org-crt-chain.pem;
ssl_certificate_key /etc/nginx/conf.d/pank.org-key.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
server_name test1.pank.org;
ssl_certificate /etc/nginx/conf.d/pank.org-crt-chain.pem;
ssl_certificate_key /etc/nginx/conf.d/pank.org-key.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
add_header X-Proxy-Cache $upstream_cache_status;
proxy_pass http://192.168.0.27;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.0.27;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}若後端有多台,建立多個 conf 即可
有設定 proxy_set_header X-Forwarded-For 會帶 X-Forwarded-For 到 backend server
Apache Reverse Proxy with SSL
憑證掛在 Reverse Proxy, 內部走 HTTP
<VirtualHost *:443>
若後端有多台,建立多個 VirtualHost 區塊即可
Apache 預設就會帶 X-Forwarded-For 到 backend server,不用特別設定
<VirtualHost *:443>
ServerName test1.pank.org
ServerAdmin pank@pank.org
ErrorLog "/var/log/httpd/test1_error_log"
TransferLog "/var/log/httpd/test1_access_log"
SSLEngine on
ProxyPass / http://192.168.0.27/
ProxyPassReverse / http://192.168.0.27/
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/etc/httpd/conf.d/pank.org-crt.pem"
SSLCertificateKeyFile "/etc/httpd/conf.d/pank.org-key.pem"
SSLCertificateChainFile /etc/httpd/conf.d/chain.pem
</VirtualHost>ServerAdmin pank@pank.org
ErrorLog "/var/log/httpd/test1_error_log"
TransferLog "/var/log/httpd/test1_access_log"
SSLEngine on
ProxyPass / http://192.168.0.27/
ProxyPassReverse / http://192.168.0.27/
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/etc/httpd/conf.d/pank.org-crt.pem"
SSLCertificateKeyFile "/etc/httpd/conf.d/pank.org-key.pem"
SSLCertificateChainFile /etc/httpd/conf.d/chain.pem
若後端有多台,建立多個 VirtualHost 區塊即可
Apache 預設就會帶 X-Forwarded-For 到 backend server,不用特別設定
2023年8月3日 星期四
yt-dlp - youtube-dl replacement
youtube-dl 之前是一個好用的視頻下載工具,但在 2020 年 10 月,被 RIAA 要求下架,
Github 也關閉了它及其他 fork 的專案
但在很多使用者抱怨下,2020 年 11 月 Github 恢復了 youtube-dl 的專案,
但是近來都沒更新了,最後更新日期是 2021 年 12 月
yt-dlp 是 youtube-dl 的 fork,仍常常更新,可視為 youtube-dl 的替代品
Github 也關閉了它及其他 fork 的專案
但在很多使用者抱怨下,2020 年 11 月 Github 恢復了 youtube-dl 的專案,
但是近來都沒更新了,最後更新日期是 2021 年 12 月
yt-dlp 是 youtube-dl 的 fork,仍常常更新,可視為 youtube-dl 的替代品
2023年7月3日 星期一
Simple traffic shapping with iptables
使用 iptables 限速
範例: Linux Gateway, 區網的網段是 192.168.0.0/24
要限制每個 IP 都有上傳下載 16M/16M bps
iptables -A FORWARD -d 192.168.0.0/24 -m hashlimit --hashlimit-name ratelimitin --hashlimit-mode dstip --hashlimit-above 2048kb/s -j DROP
iptables -A FORWARD -s 192.168.0.0/24 -m hashlimit --hashlimit-name ratelimitin --hashlimit-mode srcip --hashlimit-above 2048kb/s -j DROP
Rule 要分兩個方向來下,兩這條分別是下載及上傳
16M bps = 16384 k bps = 2048 kb/s
實測結果還算準
範例: Linux Gateway, 區網的網段是 192.168.0.0/24
要限制每個 IP 都有上傳下載 16M/16M bps
iptables -A FORWARD -d 192.168.0.0/24 -m hashlimit --hashlimit-name ratelimitin --hashlimit-mode dstip --hashlimit-above 2048kb/s -j DROP
iptables -A FORWARD -s 192.168.0.0/24 -m hashlimit --hashlimit-name ratelimitin --hashlimit-mode srcip --hashlimit-above 2048kb/s -j DROP
Rule 要分兩個方向來下,兩這條分別是下載及上傳
16M bps = 16384 k bps = 2048 kb/s
實測結果還算準
2023年6月27日 星期二
Get Public IP Address from OpenDNS
一般取得所在 Public IP 都是用 Web 服務取得,例如:
curl ip4.tw
curl ifconfig.co
OpenDNS 有提供一個服務,對他們的 name server 查 myip.opendns.com 會回應來源 IP
dig +short myip.opendns.com @resolver1.opendns.com
host myip.opendns.com resolver1.opendns.com
發現若環境同時有 IPv4+IPv6 可能會不正常,因為兩個 IP 都有的話,通常會走 IPv6 的路由,用 IPv6 路由去查 A 記錄導致無資料
保險一點,指令要區分 IPv4、IPv6
dig -4 +short A myip.opendns.com @resolver1.opendns.com
dig -6 +short AAAA myip.opendns.com @resolver1.opendns.com
curl ip4.tw
curl ifconfig.co
OpenDNS 有提供一個服務,對他們的 name server 查 myip.opendns.com 會回應來源 IP
dig +short myip.opendns.com @resolver1.opendns.com
host myip.opendns.com resolver1.opendns.com
發現若環境同時有 IPv4+IPv6 可能會不正常,因為兩個 IP 都有的話,通常會走 IPv6 的路由,用 IPv6 路由去查 A 記錄導致無資料
保險一點,指令要區分 IPv4、IPv6
dig -4 +short A myip.opendns.com @resolver1.opendns.com
dig -6 +short AAAA myip.opendns.com @resolver1.opendns.com
2023年6月18日 星期日
Import Rocky Linux 9 to WSL
需先安裝 XZ Utils for Windows 把 xz.exe 放在 PATH 有指到的地方
curl -LOs https://github.com/rocky-linux/sig-cloud-instance-images/raw/Rocky-9.2.20230513-Base-x86_64/layer.tar.xz
上面的 layer.tar.xz 是官方的網址,其他版本網址可到 sig-cloud-instance-images 選擇 Branch
xz -d layer.tar.xz
wsl --import RockyLinux9 D:\WSL\RockyLinux9 layer.tar
Distro 名稱 RockyLinux9 及資料目錄名稱 D:\WSL\RockyLinux9 請依自身環境調整
wsl -d RockyLinux9
即完成進入 RockyLinux9 WSL
ref. Import any Linux distribution to use with WSL
curl -LOs https://github.com/rocky-linux/sig-cloud-instance-images/raw/Rocky-9.2.20230513-Base-x86_64/layer.tar.xz
上面的 layer.tar.xz 是官方的網址,其他版本網址可到 sig-cloud-instance-images 選擇 Branch
xz -d layer.tar.xz
wsl --import RockyLinux9 D:\WSL\RockyLinux9 layer.tar
Distro 名稱 RockyLinux9 及資料目錄名稱 D:\WSL\RockyLinux9 請依自身環境調整
wsl -d RockyLinux9
即完成進入 RockyLinux9 WSL
ref. Import any Linux distribution to use with WSL
2023年5月20日 星期六
Migrate Google Compute Engine VM image to local
想要把 Google Compute Engine VM 備份,或者 clone 一份到 local 做測試
先關機建立映像檔,再把映像檔匯出到 Bucket (可以選擇匯出格式 vmdk、vhdx 等),然後就可以下載
但會發現在自己的環境無法開機,看起來是找不到 root
先關機建立映像檔,再把映像檔匯出到 Bucket (可以選擇匯出格式 vmdk、vhdx 等),然後就可以下載
但會發現在自己的環境無法開機,看起來是找不到 root
解決方式必需重建 initramfs
但因為找不到 root,在這個 emergency mode 無法做這個動作 (dracut -f)
需要找對應的版本的 ISO 來開機,由於系統內可能沒有跟 ISO 內一樣版號的 /lib/modules
最簡單的方式就是裝 ISO 內的 Kernel,流程上一樣會建立 initramfs
以下以 CentOS 7.9 為例:
以光碟開機進入 Rescue 模式後,選 1
chroot /mnt/sysimage
mount /dev/cdrom /mnt
cd /mnt/Packages
rpm -ivh kernel-3.10.0-1160.el7.x86_64.rpm
exit
reboot
應該就可以正常開機了
備註:
一開始畫面出現這個
Probing EDD (edd=off to disable)... ok
其實跟開不了機無關,不影響是否可以正常開機
2023年5月5日 星期五
Allow CloudFront edge server only
服務有導入 CloudFront 的話,限制只有 CloudFront edge server 來存取會較安全
JSON 資料格式
https://d7uri8nf7uskq.cloudfront.net/tools/list-cloudfront-ips
ref. Locations and IP address ranges of CloudFront edge servers
JSON 資料格式
https://d7uri8nf7uskq.cloudfront.net/tools/list-cloudfront-ips
ref. Locations and IP address ranges of CloudFront edge servers
訂閱:
文章 (Atom)
Fix Ubuntu NO_PUBKEY B53DC80D13EDEF05
Google Cloud package update failed curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyring...
-
openfortivpn 和 FortiClient VPN 相容,若不想用官方的 Client 可以試試 只是它是命令列模式,沒有 GUI 使用很簡單 openfortivpn vpn-gateway:8443 -u username 然後會提示輸入 Password 若憑...
-
啟用 Windows 10 終極效能電源計劃 powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61 設完之後, 設定 / 系統 / 電源與睡眠 / 其他電源設定 就會出現「終極效能」選項 網路上有人實測,效能...
-
以前都是用 rp-pppoe 套件裡的 adsl-setup 來設定 PPPoE 現在比較新的 Linux 已經沒有這個套件了,要用 NetworkManager 的 nmcli 來設定 設定也很簡單,準備帳號、密碼及網路卡就行了 以下範例帳號是 xxxx@hinet.net 密...
-
禁止 LINE 電腦版傳送連線診斷報告 當把 desktop.line-scdn.net 擋掉時 (ref. Disable LINE desktop force update ), LINE 會傳送連線診斷報告到 nelo2-col.linecorp.com, 內容 body ...
-
RouterOS 的管理工具 winbox,因為還不支援 UTF-8, 雖然可以在 Wireless 設定中文的 SSID,但是實際上會看到亂碼, WiFi 的 SSID 是走 UTF-8 編碼,需要把 UTF-8 中文轉成 HEX 碼,再用指令設定 寫了一個小工具提供大家使用...
-
禁止 LINE 電腦版自動或強制更新的方法 LINE 電腦版啟動都會去連這個更新資訊檔 https://desktop.line-scdn.net/win/v1/real/update_info.json 內容大概長這樣 可以看出針對各版本的更新 type 有 force, ...
-
電腦不符合 Windows 11 需求,也可以安裝 Windows 11 安裝流程第一個畫面按 Shift-F10 開啟 CMD 下指令 reg add HKLM\System\Setup\LabConfig /v "BypassTPMCheck" /t RE...
-
微軟數學解題工具 Microsoft Math Solver 學習數學的輔助工具,功能強大,有解題步驟及解釋,也有 APP
-
Amazon Lightsail now supports IPv6 AWS Lightsail 到 2021 年才開始支援 IPv6 若機器是之前開的,需手動將它 enable,並加上一些參數 適用 CentOS 或 Amazon Linux 環境 /etc/sysconfig...
-
Windows 的 NFS Client 從 Windows 7 之後就內建了,但預設沒有開啟, 要到 設定 / 應用程式 / 程式與功能 / 開啟或關閉 Windows 功能 開啟 Client for NFS 但是預設的情況下,遇到中文檔名會有亂碼, 到 設定 / 時間與語言...