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 -
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)
10 minutes file sharing service
https://tmp.pank.org 這個服務方便臨時交換檔案,檔案存活時間 10 分鐘,檔案大小上限 25MB 可以經由 curl 上傳或 Web 上傳 curl 上傳範例,上傳完會顯示下載網址 # curl -sT 10mb.zip tmp.pank.org 103901...
-
xrdp 是 Linux 版的 RDP server (遠端桌面) 它運作時需要 Xvnc 的 libvnc.so, 所以安裝時需要連同 VNC 一起安裝(只需 minimal) dnf -y install xrdp tigervnc-server-minimal system...
-
以前都是用 rp-pppoe 套件裡的 adsl-setup 來設定 PPPoE 現在比較新的 Linux 已經沒有這個套件了,要用 NetworkManager 的 nmcli 來設定 設定也很簡單,準備帳號、密碼及網路卡就行了 以下範例帳號是 xxxx@hinet.net 密...
-
本例是從 8.0U3 升到 8.0U3d,若從更舊的版本升級,不確定是否適用 先把所有 VM 關機,進入維護模式 把 depot 升級檔 VMware-ESXi-8.0U3d-24585383-depot.zip 放到機器內 ssh ESXi 先查看 depot 有那些 Prof...
-
RouterOS 在 7 版以後支援 WireGuard 註: WireGuard 在 Linux Kernel 5.6 版開始內建 設定滿簡單的,在選單 WireGuard New Interface,Private Key 及 Public Key 不用填,會自動產生 在 I...
-
http://mirror01.idc.hinet.net HiNet 這個網址關了,要高速下載 Linux ISO 少了一個地方,感謝 HiNet 默默服務了多年 測了幾個 TW mirror 站,推 TWDC 台灣數位串流,常見的 Linux 都有,速度超快 https://...
-
禁止 LINE 電腦版自動或強制更新的方法 LINE 電腦版啟動都會去連這個更新資訊檔 https://desktop.line-scdn.net/win/v1/real/update_info.json 內容大概長這樣 可以看出針對各版本的更新 type 有 force, ...
-
現在自架的 Mail Server 若沒有簽章,寄出的信件有很大的機會被擋或歸類在垃圾信 所以 SPF + DKIM 已經是必要的設定 環境 CentOS + Postfix,文中的域名均以 yourdomain.com 作為範例 安裝所需套件 yum -y install py...
-
Bracketed Paste Mode 是 Terminal 為了區分手動輸入及剪貼簿貼上的一種模式, 啟用此模式,貼上的文字區塊會被起始控制碼 ESC [ 200 ~ 及結束控制碼 ESC [ 201 ~ 包住 例如在編輯器貼上一段已經排版好的程式碼,若沒有啟用 Brack...
-
RustDesk 使用上跟 Anydesk, Teamviewer 差不多,也是用 ID + Password 就可以連線 其優點是開源,可以自架 ID/Relay Server 在 Client 裝好的情況下,直接是可以使用的,預設應該是使用 RustDesk 的公共 Ser...
-
需先安裝 XZ Utils for Windows 把 xz.exe 放在 PATH 有指到的地方 curl -LOs https://github.com/rocky-linux/sig-cloud-instance-images/raw/Rocky-9.2.20230513...