顯示具有 系統管理 標籤的文章。 顯示所有文章
顯示具有 系統管理 標籤的文章。 顯示所有文章

2026年10月21日 星期三

FreeBSD 時間設定

時區設定
tzsetup
cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime

adjkerntz -a

NTP 設定
編輯 /etc/ntp.conf
# 指定僅向 tock.stdtime.gov.tw 進行對時
server tock.stdtime.gov.tw iburst

# 預設拒絕外部所有不信任的存取(安全性設定)
restrict default limited kod nomodify notrap noquery nopeer
restrict source limited kod nomodify notrap noquery

# 開放本機無限制存取
restrict 127.0.0.1
restrict ::1

# 閏秒清單
leapfile "/var/db/ntpd.leap-seconds.list"

啟用服務
service  ntpd onestart

FreeBSD Sylve Jail 設定 xrdp + 中文輸入

pkg install -y xrdp xfce xorg xorgxrdp
pkg install -y xorg xfce xfce4-goodies
pkg install -y noto-tc
pkg install -y zh-CJKUnifonts
pkg install -y zh-CNS11643-font
fc-cache -f -v

pkg install -y fcitx5 fcitx5-configtool fcitx5-gtk2 fcitx5-gtk3 fcitx5-gtk4 fcitx5-qt5 fcitx5-qt6
pkg install -y zh-fcitx5-chewing zh-fcitx5-chinese-addons zh-fcitx5-table-extra zh-fcitx5-table-other

service dbus start
service xrdp start
service xrdp-sesman start 

XRDP 設定 ~/.startwm.sh
編輯 /usr/local/etc/xrdp/startwm.sh
# 系統選單與桌面語系
export LANG=zh_TW.UTF-8
export LC_CTYPE=zh_TW.UTF-8
export LC_MESSAGES=zh_TW.UTF-8

# Fcitx5 輸入法模組
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

exec startxfce4

修正 /usr/local/etc/xrdp/key.pem /usr/local/etc/xrdp/cert.pem
service xrdp stop
rm -f /usr/local/etc/xrdp/cert.pem /usr/local/etc/xrdp/key.pem

# OpenSSL 手動生成現代化 SHA256 憑證 (有效期限 3650 天)
openssl req -x509 -newkey rsa:2048 -sha256 -nodes \
  -keyout /usr/local/etc/xrdp/key.pem \
  -out /usr/local/etc/xrdp/cert.pem \
  -days 3650 \
  -subj "/CN=FreeBSD-Jail-xrdp"

# 修正檔案權限,確保 xrdp 帳號可存取
chown _xrdp:_xrdp /usr/local/etc/xrdp/key.pem /usr/local/etc/xrdp/cert.pem
chmod 600 /usr/local/etc/xrdp/key.pem
chmod 644 /usr/local/etc/xrdp/cert.pem

2026年10月20日 星期二

FreeBSD 更新

更新 FreeBSD 系統本體 (Base System)
檢查並下載系統更新檔
freebsd-update fetch

安裝下載好的系統更新
freebsd-update install

更新第三方套件 (Pkg)
pkg update
pkg upgrade

清理無用的舊版套件與快取
pkg autoremove
pkg clean -a

FreeBSD 安裝 sshfs

pkg install -y fusefs-sshfs

載入 FUSE 核心模組
kldload fusefs

設定開機載入 fusefs
sysrc -f /boot/loader.conf fusefs_load="YES"

FreeBSD 啟用 Serial Console(透過 Serial 登入系統)

編輯 /boot/loader.conf,加入以下內容以啟動 Boot Loader 的 Serial 輸出:
boot_multicons="YES"
boot_serial="YES"
comconsole_speed="115200"
console="comconsole,vidconsole"

編輯 /etc/ttys 修改
ttyu0   "/usr/libexec/getty 3wire.115200"   vt100   on  secure

2026年10月19日 星期一

NAT LoopBack Iptable 設定範例

IF=vmbr0
PORT_FROM=3142
PORT_TO=3142
DEST=172.16.255.8
LAN_NET="172.16.0.0/16"

# 1. DNAT:將外部或內部存取 Port 的流量轉發至目標 VM/LXC
# (移除 -i $IF 限制,允許來自內網與外網的流量都能觸發轉發)
iptables -t nat -A PREROUTING -p tcp --dport $PORT_FROM -j DNAT --to $DEST:$PORT_TO

# 2. NAT Loopback (Hairpin SNAT):
# 當來源為內網 (LAN_NET) 且目的地為 DEST:PORT_TO 時,將來源 IP 改寫為防火牆的 LAN IP
iptables -t nat -A POSTROUTING -s $LAN_NET -d $DEST -p tcp --dport $PORT_TO -j MASQUERADE

# 3. FORWARD:允許此轉發流量通過防火牆
iptables -A FORWARD -p tcp -d $DEST --dport $PORT_TO -j ACCEPT

2026年10月16日 星期五

FreeBSD Sylve 增加 pam 登入方式

編輯  /usr/local/etc/sylve/config.json 修改
"auth": {
        "enablePAM": true 
    },

service sylve restart

2026年10月12日 星期一

FreeBSD 15安裝 xrdp + xfce + fcitx 中文輸入法

pkg install xorg xfce xfce4-goodies
pkg install noto-tc
pkg install zh-CJKUnifonts
pkg install zh-CNS11643-font
fc-cache -f -v

pkg install fcitx5 fcitx5-configtool fcitx5-gtk2 fcitx5-gtk3 fcitx5-gtk4 fcitx5-qt5 fcitx5-qt6
pkg install -y zh-fcitx5-chewing zh-fcitx5-chinese-addons zh-fcitx5-table-extra zh-fcitx5-table-other

XRDP 設定 ~/.startwm.sh
# 系統選單與桌面語系
export LANG=zh_TW.UTF-8
export LC_CTYPE=zh_TW.UTF-8
export LC_MESSAGES=zh_TW.UTF-8

# Fcitx5 輸入法模組
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

2026年10月8日 星期四

FreeBSD 15x 安裝 xrdp

pkg install -y xfce
pkg install -y dbus

sysrc dbus_enable="YES"
sysrc xrdp_enable="YES"
sysrc xrdp_sesman_enable="YES"

service dbus start
service xrdp start
service xrdp-sesman start

echo "exec startxfce4" > ~/.startwm.sh
chmod +x ~/.startwm.sh

編輯 /usr/local/etc/xrdp/startwm.sh
exec ~/.startwm.sh

xrdp 連線 unknown target image 警告

編輯 /usr/local/etc/xrdp/xrdp.ini [Globals] 區段,新增或修改
cliprdr_image_conversion=false

FreeBSD 15.x 安裝 xfce + 中文輸入法

pkg install -y xorg xfce xfce4-goodies
pkg install -y noto-tc

#pkg install -y zh-CJKUnifonts
#pkg install -y zh-CNS11643-font

fc-cache -f -v

pkg install -y fcitx5 fcitx5-configtool fcitx5-gtk2 fcitx5-gtk3 fcitx5-gtk4 fcitx5-qt5 fcitx5-qt6
pkg install -y zh-fcitx5-chewing zh-fcitx5-chinese-addons zh-fcitx5-table-extra zh-fcitx5-table-other

2026年10月5日 星期一

BreeBSD Bridge 筆記

ifconfig bridge create name vmbr0
ifconfig vmbr0 addm igb0
ifconfig vmbr0 up

sysrc cloned_interfaces+="bridge0"
sysrc ifconfig_bridge0_name="vmbr0"
sysrc ifconfig_vmbr0="addm igb0 up"

ifconfig vmbr0
ifconfig vmbr0 deletem igb0
ifconfig vmbr0 down
ifconfig vmbr0 destroy

sysrc cloned_interfaces-="bridge0"
sysrc -x ifconfig_bridge0_name
sysrc -x ifconfig_vmbr0

2026年9月14日 星期一

Apache2 設定編碼方式

編輯  /etc/apache2/conf-available/charset.conf 加入
AddDefaultCharset UTF-8

編輯 .htaccess
AddDefaultCharset UTF-8
AddType 'text/html; charset=UTF-8' .html .htm
AddType 'application/json; charset=UTF-8' .json




2026年8月25日 星期二

Open WebUI 設定為免帳號、免登入使用 Docker 執行

 docker run -d -p 3000:8080 \
  -e WEBUI_AUTH=False \
  -e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
  --add-host=host.docker.internal:host-gateway \
  -v open-webui-data:/app/backend/data \
  --name open-webui \
  --restart always \
  ghcr.io/open-webui/open-webui:main

LEAF Shorewall NAT LOOPBACK 範例

編輯 /etc/shorewall/interfaces 增加 routeback
net             eth0                    dhcp
loc             eth1                    dhcp,routeback

編輯 /etc/shorewall/nat
100.109.54.55   eth0            192.168.9.55    Yes             No

編輯/etc/shorewall/snat
MASQUERADE     192.168.9.0/24 eth1 

編輯  /etc/shorewall/rules
SSH(ACCEPT)     net:100.109.54.0/24  loc:192.168.9.55
#DNAT       net      loc:192.168.9.55:22   tcp     22   -   100.109.54.55
#DNAT       loc      loc:192.168.9.55      tcp     22   -   100.109.54.55

Nginx Reverse Proxy 設定範例

 server {
 listen 80 ;
 listen [::]:80 ;

    server_name 192.168.26.162;
    set $backend_librenms "http://192.168.255.1";
    location / {
        # 注意:目標網址結尾「不要」加斜線 /
        # 這樣存取 /ipam/xxx 時,會自動轉發至 http://hostname2/ipam/xxx
        proxy_pass $backend_librenms;
        # 傳送原始請求標頭
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # 處理後端發出的 301/302 重導向(將 hostname2 替換為 hostname1)
        proxy_redirect $backend_librenms $http_host;

        # 停用快取與調整超時限制(適合 phpIPAM / NetBox 等管理工具)
        proxy_buffering off;
        proxy_read_timeout 90;
    }

    set $backend_ipam "http://192.168.255.2";
    location /ipam {
        # 注意:目標網址結尾「不要」加斜線 /
        # 這樣存取 /ipam/xxx 時,會自動轉發至 http://hostname2/ipam/xxx
        proxy_pass $backend_ipam;

        # 傳送原始請求標頭
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # 處理後端發出的 301/302 重導向(將 hostname2 替換為 hostname1)
        proxy_redirect $backend_ipam $http_host;

        # 停用快取與調整超時限制(適合 phpIPAM / NetBox 等管理工具)
        proxy_buffering off;
        proxy_read_timeout 90;
    }
}

2026年7月28日 星期二

IDs assigned but not accepted

#Nginx 設定
http {
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
ssl_session_tickets on;
}

測試
openssl s_client -connect host:443 -reconnect -state

HSTS(Strict Transport Security)

#Nginx 設定
server {
    listen 443 ssl http2;
    server_name example.com;
    # 啟用 HSTS(建議維持至少 1 年 = 31536000 秒)
    # includeSubDomains: 套用至所有子網域
    # preload: 允許加入瀏覽器預載清單
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
}

#Apache2 設定
<VirtualHost *:443>
    ServerName example.com   
    # 啟用 HSTS
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</VirtualHost>

測試
chrome://net-internals/#hsts
curl -I https://127.0.0.1
Plaintext
HTTP/2 200
...
strict-transport-security: max-age=31536000; includeSubDomains; preload
...

Qualys SSL Labs(權威檢測)
網址:https://www.ssllabs.com/ssltest/

HSTS Preload 狀態檢查
網址:https://hstspreload.org/

2026年7月23日 星期四

請透過 Squid Proxy 下載 docker hub 公開 image

 #異動 docker 設定
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
Environment="HTTP_PROXY=http://squid:3128"
Environment="HTTPS_PROXY=http://squid:3128"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com"
EOF

#重新載入設定並重啟 Docker
sudo systemctl daemon-reload
sudo systemctl restart docker

#確認是否生效
sudo docker info | grep -i proxy

Squid Proxy 開放網址
auth.docker.io
registry-1.docker.io
production.cloudfront.docker.com

透過 Squid Proxy 下載 ollama models

#編輯 /etc/systemd/system/ollama.service
[Service] 區塊中加入
Environment="HTTPS_PROXY=http://squid:3128"
Environment="HTTP_PROXY=http://squid:3128"

# 重新載入並重啟 Ollama
sudo systemctl daemon-reload
sudo systemctl restart ollama

#確認是否生效
sudo systemctl show ollama --property=Environment


Squid Proxy 開放網址
ollama.com
registry.ollama.ai
.cloudflarestorage.com