Archive for the ‘Linux’ Category
ติดตั้ง OpenVPN ให้รองรับ 1000 Client

OpenVPN
172.16.16.0/22
Network
172.16.16.0
Mask
255.255.252.0
Range
172.16.16.2-172.16.19.254
1022 IP
**** เพียงพอสำหรับ 1000 Client ****
1. Install
root@np:/home/teee# apt install openvpn easy-rsa openssl ca-certificates -y
2. EasyRSA
root@np:/home/teee# make-cadir /etc/openvpn/easy-rsa
root@np:/home/teee# cd /etc/openvpn/easy-rsa
root@np:/etc/openvpn/easy-rsa# ./easyrsa init-pki
Using Easy-RSA ‘vars’ configuration:
* /etc/openvpn/easy-rsa/vars
Notice
——
‘init-pki’ complete; you may now create a CA or requests.
Your newly created PKI dir is:
* /etc/openvpn/easy-rsa/pki
Using Easy-RSA configuration:
* /etc/openvpn/easy-rsa/vars
root@np:/etc/openvpn/easy-rsa# ./easyrsa build-ca nopass
Using Easy-RSA ‘vars’ configuration:
* /etc/openvpn/easy-rsa/vars
…+++++++++++++++++++++++++++++++++++++++*…………+.+…..+…+…………………….+..+…….+..+…+.+..+…….+++++++++++++++++++++++++++++++++++++++*………..+……….+………..+………+.+…+……+…..+….+………+…..+…..+……….+..+……………+….+…+……..+…+……+.+………+…..+.++++++
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:(Your Server-Name)
Notice
——
CA creation complete. Your new CA certificate is at:
* /etc/openvpn/easy-rsa/pki/ca.crt
Create an OpenVPN TLS-AUTH|TLS-CRYPT-V1 key now: See ‘help gen-tls’
Build-ca completed successfully.
——
ตั้งชื่อ CA เช่น. Your Server-Name-CA
สร้าง Server Certificate
root@np:/etc/openvpn/easy-rsa# ./easyrsa build-server-full server nopass
Using Easy-RSA ‘vars’ configuration:
* /etc/openvpn/easy-rsa/vars
.+…+..+++++++++++++++++++++++++++++++++++++++*….+…….+…+…..+++++++++++++++++++++++++++++++++++++++*….+….+……+…+..+…+…………+….+…+..+……+………+.+..+…+….+…+………..+…….+……..+.++++++
—–
Notice
——
Private-Key and Public-Certificate-Request files created.
Your files are:
* req: /etc/openvpn/easy-rsa/pki/reqs/server.req
* key: /etc/openvpn/easy-rsa/pki/private/server.key
You are about to sign the following certificate:
Requested CN: ‘server’
Requested type: ‘server’
Valid for: ‘825’ days
subject=
commonName = server
Type the word ‘yes’ to continue, or any other input to abort.
Confirm requested details: yes (ตอบ yes)
Using configuration from /etc/openvpn/easy-rsa/pki/634563e8/temp.6.1
Check that the request matches the signature
Signature ok
The Subject’s Distinguished Name is as follows
commonName :ASN.1 12:’server’
Certificate is to be certified until Oct 9 09:52:01 2028 GMT (825 days)
Write out database with 1 new entries
Database updated
Notice
——
Inline file created:
* /etc/openvpn/easy-rsa/pki/inline/private/server.inline
Notice
——
Certificate created at:
* /etc/openvpn/easy-rsa/pki/issued/server.crt
DH
root@np:/etc/openvpn/easy-rsa# ./easyrsa gen-dh
Using Easy-RSA ‘vars’ configuration:
* /etc/openvpn/easy-rsa/vars
Generating DH parameters, 2048 bit long safe prime
……………………………………………………………………………………………………………………………………………………………………………….++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*
DH parameters appear to be ok.
Notice
——
DH parameters of size 2048 created at:
* /etc/openvpn/easy-rsa/pki/dh.pem
TLS Key
root@np:/etc/openvpn/easy-rsa# openvpn –genkey secret ta.key
Client
root@np:/etc/openvpn/easy-rsa# ./easyrsa build-client-full client01 nopass<—ทดลองสร้าง Client01
Using Easy-RSA ‘vars’ configuration:
* /etc/openvpn/easy-rsa/vars
.+……………+..+.+..+….+…..+++++++++++++++++++++++++++++++++++++++*…..+.+…+…..+…………….+…+..+…+…………+.+..+…+…….+…+…..+.+……+…+……………………+…+..+…………+……………+…+.+..+….+…++++++
—–
Notice
——
Private-Key and Public-Certificate-Request files created.
Your files are:
* req: /etc/openvpn/easy-rsa/pki/reqs/client01.req
* key: /etc/openvpn/easy-rsa/pki/private/client01.key
You are about to sign the following certificate:
Requested CN: ‘client01’
Requested type: ‘client’
Valid for: ‘825’ days
subject=
commonName = client01
Type the word ‘yes’ to continue, or any other input to abort.
Confirm requested details: yes
Using configuration from /etc/openvpn/easy-rsa/pki/3020d3d9/temp.6.1
Check that the request matches the signature
Signature ok
The Subject’s Distinguished Name is as follows
commonName :ASN.1 12:’client01′
Certificate is to be certified until Oct 9 09:55:58 2028 GMT (825 days)
Write out database with 1 new entries
Database updated
Notice
——
Inline file created:
* /etc/openvpn/easy-rsa/pki/inline/private/client01.inline
Notice
——
Certificate created at:
* /etc/openvpn/easy-rsa/pki/issued/client01.crt
3.Copy Files
root@np:/etc/openvpn/easy-rsa# mkdir /etc/openvpn/server
mkdir: cannot create directory ‘/etc/openvpn/server’: File exists
root@np:/etc/openvpn/easy-rsa# ls -l /etc/openvpn/server/
total 0
root@np:/etc/openvpn/easy-rsa# cp pki/ca.crt pki/dh.pem ta.key pki/issued/server.crt pki/private/server.key /etc/openvpn/server/
root@np:/etc/openvpn/easy-rsa# ls -l /etc/openvpn/server/
total 24
-rw——- 1 root root 1196 Jul 7 16:58 ca.crt
-rw——- 1 root root 428 Jul 7 16:58 dh.pem
-rw——- 1 root root 4499 Jul 7 16:58 server.crt
-rw——- 1 root root 1704 Jul 7 16:58 server.key
-rw——- 1 root root 636 Jul 7 16:58 ta.key
4. Server Config
root@np:/etc/openvpn/easy-rsa# nano /etc/openvpn/server/server.conf
port 1194
proto udp
dev tun
user nobody
group nogroup
persist-key
persist-tun
topology subnet
server 172.16.16.0 255.255.252.0
ifconfig-pool-persist ipp.txt
push “route 172.16.19.0 255.255.255.0”
#push “redirect-gateway def1” <— ปิดไว้
push “dhcp-option DNS 1.1.1.1”
push “dhcp-option DNS 8.8.8.8”
keepalive 10 120
cipher AES-256-GCM
data-ciphers AES-256-GCM:AES-128-GCM
auth SHA256
tls-version-min 1.2
tls-crypt ta.key
ca ca.crt
cert server.crt
key server.key
dh dh.pem
verb 3
explicit-exit-notify 1
=== SAVE ===
#push “redirect-gateway def1” <— ปิดไว้
ผู้ใช้ OpenVPN จะเข้าเฉพาะเครือข่ายภายใน แต่ Internet ยังออกผ่าน Wi-Fi/4G ของเครื่องเอง ซึ่งจะไม่เปลืองแบนด์วิดท์ของ VPS
Push Route เฉพาะ Network ภายใน ให้เหลือประมาณนี้
push “route 172.16.16.0 255.255.252.0”
push “route 172.16.19.0 255.255.255.0”
push “dhcp-option DNS 1.1.1.1”
push “dhcp-option DNS 8.8.8.8”
5. Enable Routing
nano /etc/sysctl.conf
net.ipv4.ip_forward=1 <- เพิ่ม
sysctl -p <–Apply
6. IP Tables
root@np:/home/teee# iptables -A INPUT -p udp –dport 1194 -j ACCEPT
iptables -I INPUT 1 -i tun0 -j ACCEPT
iptables -A INPUT -p udp –dport 1194 -j ACCEPT
iptables -A FORWARD -i tun0 -o wg0 -j ACCEPT
iptables -A FORWARD -i wg0 -o tun0 -m conntrack –ctstate RELATED,ESTABLISHED -j ACCEPT
iptables-save > /etc/iptables/rules.v4
ถ้าจะออก Internet ผ่าน OpenVPN ต้องเพิ่ม
iptables -t nat -A POSTROUTING -s 172.16.16.0/22 -o eth0 -j MASQUERADE
แต่ถ้าจะใช้เฉพาะเข้าหา FreeSwitch ไม่จำเป็น
7. Start OPENVPN
root@np:/home/teee# systemctl enable openvpn-server@server
Created symlink ‘/etc/systemd/system/multi-user.target.wants/openvpn-server@server.service’ → ‘/usr/lib/systemd/system/openvpn-server@.service’.
root@np:/home/teee# systemctl start openvpn-server@server
8. Check Status
root@np:/home/teee# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:1194 0.0.0.0:* 423784/openvpn
root@np:/home/teee# ifconfig
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 172.16.16.1 netmask 255.255.252.0 destination 172.16.16.1
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
==== ทดสอบ ควรได้ผลดังนี้. ======
# เข้า OpenVPN Server
ping 172.16.16.1
# เข้า WireGuard / FreeSWITCH
ping 172.16.19.1
# เข้า FreeSWITCH ถ้ามี IP อื่น
ping 172.16.19.x
# Internet
ping 8.8.8.8
# DNS
ping google.com
=== แก้ไขเพิ่มเติม ===
root@np:/etc/systemd/system# nano /usr/lib/systemd/system/openvpn-server@.service
GNU nano 8.4 /usr/lib/systemd/system/openvpn-server@.service *
[Unit]
Description=OpenVPN service for %I
After=network-online.target
Wants=network-online.target
Documentation=man:openvpn(8)
Documentation=https://openvpn.net/community-resources/reference-manual-for-openvpn-2-6/
Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
[Service]
Type=notify
PrivateTmp=true
WorkingDirectory=/etc/openvpn/server
ExecStart=/usr/sbin/openvpn –status %t/openvpn-server/status-%i.log –status-version 2 –suppress-timestamps –config %i.conf
CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SETPCAP CAP_SYS_CHROOT CAP_DAC_OVERRIDE CAP_AU>
LimitNOFILE=65535 <—- เพิ่มบรรทัดนี้
TasksMax=infinity <—- เพิ่มบรรทัดนี้
OOMScoreAdjust=-900 <—- เพิ่มบรรทัดนี้
LimitNPROC=10 <– เปลี่ยนเป็น 4096
DeviceAllow=/dev/null rw
DeviceAllow=/dev/net/tun rw
ProtectSystem=true
ProtectHome=true
KillMode=process
RestartSec=5s
Restart=on-failure
[Install]
WantedBy=multi-user.target
===SAVE===
nano /etc/sysctl.conf
net.ipv4.ip_forward = 1
# Connection Queue
net.core.somaxconn=4096
# Socket Buffer
net.core.rmem_max=16777216
net.core.wmem_max=16777216
# Local Port Range
net.ipv4.ip_local_port_range=10240 65535
===SAVE===
มีอีกชุดที่แนะนำเพิ่ม
เนื่องจากคุณตั้งเป้า OpenVPN + WireGuard + FreeSWITCH รองรับประมาณ 1000 Users แนะนำใช้ชุดนี้แทน เพราะครบกว่า
#######################################################
# OpenVPN / WireGuard / FreeSWITCH Performance
#######################################################
# Enable Routing
net.ipv4.ip_forward=1
# TCP Queue
net.core.somaxconn=4096
# Socket Buffers
net.core.rmem_default=1048576
net.core.wmem_default=1048576
net.core.rmem_max=16777216
net.core.wmem_max=16777216
# UDP Memory
net.ipv4.udp_mem=3145728 4194304 6291456
# Port Range
net.ipv4.ip_local_port_range=10240 65535
# Reverse Path Filter
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
# SYN Queue
net.ipv4.tcp_max_syn_backlog=4096
# TIME_WAIT
net.ipv4.tcp_fin_timeout=15
===SAVE===
root@np:/etc/systemd/system# systemctl daemon-reload
root@np:/etc/systemd/system# systemctl restart openvpn-server@server
9. สคริต์สร้าง Client เชื่อมต่อ OpenVPN.
#nano make-ovpn.sh
===============================
#!/bin/bash
set -e
EASYRSA=”/etc/openvpn/easy-rsa”
if [ $# -ne 1 ]; then
echo “Usage: $0 ”
exit 1
fi
CLIENT=”$1″
CA=”$EASYRSA/pki/ca.crt”
CERT=”$EASYRSA/pki/issued/${CLIENT}.crt”
KEY=”$EASYRSA/pki/private/${CLIENT}.key”
TLSKEY=”$EASYRSA/ta.key”
OUT=”/root/${CLIENT}.ovpn”
SERVER_IP=”xxx.xxx.xxx.xxx” <—(Your Public IP) SERVER_PORT=”1194″ # ตรวจสอบไฟล์ for FILE in “$CA” “$CERT” “$KEY” “$TLSKEY” do if [ ! -f “$FILE” ]; then echo “Missing file:” echo “$FILE” exit 1 fi done echo “Creating $OUT” cat > “$OUT” <<EOF
client
dev tun
proto udp
remote ${SERVER_IP} ${SERVER_PORT}
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-GCM
data-ciphers AES-256-GCM:AES-128-GCM
auth SHA256
auth-nocache
tls-version-min 1.2
verb 3
EOF
cat “$CA” >> “$OUT”
cat >> “$OUT” <<EOF
EOF
awk ‘
/BEGIN CERTIFICATE/ {p=1}
p
/END CERTIFICATE/ {exit}
‘ “$CERT” >> “$OUT”
cat >> “$OUT” <<EOF
EOF
cat “$KEY” >> “$OUT”
cat >> “$OUT” <<EOF
EOF
cat “$TLSKEY” >> “$OUT”
cat >> “$OUT” <<EOF
EOF
chmod 600 “$OUT”
echo
echo “=======================================”
echo “Created:”
echo “$OUT”
echo “=======================================”
ใช้ได้กับ OpenVPN 2.6+, macOS, Windows, Linux, Android, iPhone โดยฝัง Certificate และ Key ทั้งหมดไว้ในไฟล์ .ovpn เพียงไฟล์เดียว
chmod +x /root/make-ovpn.sh
สร้าง Client
เช่น
root@np:# /root/make-ovpn.sh macbook
จะได้ไฟล์
/root/macbook.ovpn
ตรวจสอบ รัน
root@np:#grep tls /root/macbook.ovpn
remote-cert-tls server
tls-version-min 1.2
<tls-crypt>
</tls-crypt>
ต้องไม่มี
tls-crypt ta.key
เสร็จแล้ว Copy ไฟล์นี้ไปที่เครื่อง Clinet MAC
ที่เครื่อง MAC ติดตั้งโปรแกรม. OpenVPN Connect for macOS
https://openvpn.net/client/
เสร็จแล้วลอง Import. macbook.ovpn > openvpn Client และลองเชื่อมต่อดู

10. เปิด Status File
root@np:/etc/openvpn/server# nano server.conf
status /var/log/openvpn/openvpn-status.log <—-เพิ่มบรรทัดนี้
status-version 3 <—-เพิ่มบรรทัดนี้
===SAVE===
สร้างโฟลเดอร์
root@np:/etc/openvpn/server# mkdir -p /var/log/openvpn
root@np:/etc/openvpn/server# chown nobody:nogroup /var/log/openvpn
root@np:/etc/systemd/system# systemctl daemon-reload
root@np:/etc/systemd/system# systemctl restart openvpn-server@server
ดู status การเชื่อมต่อแบบ Realtime
root@np:/var/log/openvpn# ls -l
total 4
-rw——- 1 root root 507 Jul 13 12:36 openvpn-status.log
root@np:/var/log/openvpn# tail -f openvpn-status.log
TITLE OpenVPN 2.6.14 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] [DCO]
TIME 2026-07-13 12:36:13 1783920973
HEADER CLIENT_LIST Common Name Real Address Virtual Address Virtual IPv6 Address Bytes Received Bytes Sent Connected Since Connected Since (time_t) Username Client ID Peer ID Data Channel Cipher
HEADER ROUTING_TABLE Virtual Address Common Name Real Address Last Ref Last Ref (time_t)
GLOBAL_STATS Max bcast/mcast queue length 0
GLOBAL_STATS dco_enabled 0
END
e Real Address Last Ref Last Ref (time_t)
ROUTING_TABLE 172.16.16.2 macbook 171.100.89.168:63863 2026-07-13 12:36:41 1783921001
GLOBAL_STATS Max bcast/mcast queue length 0
GLOBAL_STATS dco_enabled 0
END
11. Logrotate
สร้างไฟล์
root@np:~# nano /etc/logrotate.d/openvpn
root@np:~# cat /etc/logrotate.d/openvpn
/var/log/openvpn/*.log {
daily
rotate 30
compress
missingok
notifempty
create 640 nobody nogroup
copytruncate
}
12. เปิด CRL (สำคัญมาก)
เวลาพนักงานลาออก ไม่ต้องเปลี่ยน CA
เพียง
./easyrsa revoke username
./easyrsa gen-crl
แล้ว
crl-verify crl.pem
13. Backup PKI
สิ่งที่ต้อง Backup
/etc/openvpn/easy-rsa/pki
โดยเฉพาะ
private/ca.key <— เก็บไว้ Offline
root@np:/etc/openvpn/easy-rsa/pki/private# ls -l
total 16
-rw——- 1 root root 1704 Jul 7 16:49 ca.key
-rw——- 1 root root 1704 Jul 7 16:55 client01.key
-rw——- 1 root root 1704 Jul 13 11:09 macbook.key
-rw——- 1 root root 1704 Jul 7 16:51 server.key
root@np:/etc/openvpn/easy-rsa/pki/private# cp ca.key /root
root@np:/etc/openvpn/easy-rsa/pki/private#
ติดตั้ง WireGuard บน Debian 13 (Trixie)
เช็คก่อนนะว่า ใช้ Linux Kernel Version อะไร
# ดู kernel version
uname -r
WireGuard ต้องการ 5.6+ และ module ถ้าไม่มี ต้อง upgrade kernel ก่อน
# ตรวจสอบ kernel ที่มีให้ติดตั้ง
apt search linux-image | grep amd64
# ติดตั้ง kernel ใหม่
apt install -y linux-image-amd64 linux-headers-amd64
# ตรวจสอบว่าติดตั้งสำเร็จ
dpkg -l | grep linux-image
แล้ว reboot:
หลัง reboot ตรวจสอบ kernel version ใหม่:
uname -r
# ควรได้ 6.x.x หรืออย่างน้อย 5.x.x
# ทดสอบ load module
modprobe wireguard
echo $? # ถ้าได้ 0 = สำเร็จ
ถ้า modprobe wireguard ผ่านแล้ว ค่อย:
systemctl enable –now wg-quick@wg0
Step 1: ติดตั้ง
apt update && apt install -y wireguard wireguard-tools
Step 2: สร้าง Key Pair บน Server
cd /etc/wireguard
umask 077
# Server keys
wg genkey | tee server_private.key | wg pubkey > server_public.key
# Client key (ทำซ้ำต่อ client)
wg genkey | tee client1_private.key | wg pubkey > client1_public.key
cat server_public.key # เก็บไว้ใส่ใน client config
cat client1_public.key # เก็บไว้ใส่ใน server config
ตรวจเช็คไฟล์ที่สร้าง
root@np:/etc/wireguard# ls
client1_private.key client1_public.key server_private.key server_public.key
root@np:/etc/wireguard# cat server_private.key
xxxxxxxxxxx(Server_Private Key)xxxxxxxxxxxxx
root@np:/etc/wireguard# cat client1_public.key
xxxxxxxxxxx(Client Public Key)xxxxxxxxxxxxx
GNU nano 8.x สร้างไฟล์ใหม่ /etc/wireguard/wg0.conf *
root@np:/etc/wireguard# cat wg0.conf
#EXAMPLE
#[Interface]
#Address = 10.10.10.11/24
#ListenPort = 51820
#PrivateKey = <server_private.key content>
# เปิด IP Forwarding (ถ้าต้องการ route traffic)
#PostUp = sysctl -w net.ipv4.ip_forward=1
#PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
#PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
# Client 1 – Laptop
#[Peer]
#PublicKey = <client1_public.key content>
#AllowedIPs = 10.10.10.111/32
# Client 2 – Phone
#[Peer]
#PublicKey = <client2_public.key content>
#AllowedIPs = 10.10.10.112/32
[Interface]
Address = 172.16.19.1/24
ListenPort = 51820
PrivateKey = xxxxxxxxxxx(Server_Private Key)xxxxxxxxxxxxx
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
# Client 1 – Laptop
[Peer]
PublicKey = xxxxxxxxxxx(Client Public Key)xxxxxxxxxxxxx
AllowedIPs = 172.16.19.10/32
ที่โปรแกรม WireGuard บน Client ให้ใส่ค่า Config นี้
[Interface]
Address = 172.16.19.10/24
PrivateKey = client1_private.key
[Peer]
PublicKey = server_public.key
Endpoint = public_ip:51820
AllowedIPs = 172.16.19.0/24
PersistentKeepalive = 25

ลองกดเชื่อมต่อ (on) จะต้องต่อไปที่ Server ได้
จะเช็คได้ยังไงว่ามี Client เชื่อมต่อเข้ามา
ดู Client ที่ connect อยู่ทั้งหมด
ตัวอย่าง output ที่ควรเห็น:
root@np:/etc/wireguard# wg show
interface: wg0
public key: xxxxxx
private key: (hidden)
listening port: 51820
peer: xxxxx
endpoint: x.x.x.x:64135 ← IP จริงของ client
allowed ips: 172.16.19.10/32
latest handshake: 2 minutes ago ← ถ้าเห็นนี้ = connected
transfer: 12.38 KiB received, 3.65 KiB sent
ถ้า ไม่เห็น latest handshake = client ยังไม่ได้ connect
เช็ค ping ไปหา client
# ping ไปที่ VPN IP ของ client
ping 172.16.19.10
root@np:/etc/wireguard# iptables -I INPUT 1 -i wg0 -j ACCEPT (เพิ่มกฏนี้ให้สามารถ ping จาก Client ไปยัง Server ได้)
ลอง Netstat -lntup ควรที่จะเห็น
root@np:/etc/wireguard# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:51820 0.0.0.0:* –
สาเหตุที่ netstat แสดง – เพราะ WireGuard ใช้ kernel module โดยตรง (wireguard.ko) ไม่มี userspace daemon ที่จะโชว์ใน process list เหมือน Program อื่น ถือว่าปกติ 100%
สร้าง Key หลาย Client พร้อมกันเลย
cd /etc/wireguard
# สร้างทีเดียว 5 client
for i in 1 2 3 4 5; do
wg genkey | tee client${i}_private.key | wg pubkey > client${i}_public.key
echo “Client $i Public Key: $(cat client${i}_public.key)”
done
เพิ่ม Peer ใน wg0.conf
cat >> /etc/wireguard/wg0.conf << EOF
# Client 2 – Phone
[Peer]
PublicKey = $(cat /etc/wireguard/client2_public.key)
AllowedIPs = 172.16.19.11/32
# Client 3 – Office PC
[Peer]
PublicKey = $(cat /etc/wireguard/client3_public.key)
AllowedIPs = 172.16.19.12/32
# Client 4
[Peer]
PublicKey = $(cat /etc/wireguard/client4_public.key)
AllowedIPs = 172.16.19.13/32
# Client 5
[Peer]
PublicKey = $(cat /etc/wireguard/client5_public.key)
AllowedIPs = 172.16.19.14/32
EOF
reload โดยไม่ต้อง restart:
# หรือ
systemctl reload wg-quick@wg0
Netplan Ubuntu
LAN
nano /etc/netplan/00-installer-config.yaml
sudo chmod 600 /etc/netplan/00-installer-config.yaml
sudo netplan apply

WiFi
sudo nano /etc/netplan/50-cloud-init.yaml

ขึ้นข้อความ -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
ข้อความนี้:
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
💡 หมายเหตุ: ข้อความ warning นี้ไม่กระทบการใช้งานปกติของระบบ แต่แก้ไขแล้วจะไม่ขึ้นทุกครั้งที่เปิด shell
เกิดจาก ระบบไม่รู้จัก locale ที่คุณตั้งค่าไว้ โดยเฉพาะ UTF-8
1. ตรวจสอบ locale ที่ติดตั้ง:
teee@san:~$ locale -a
C
C.utf8
en_US.utf8
POSIX
th_TH.utf8
คุณอาจเห็นรายการเช่น en_US.utf8 หรือ th_TH.utf8
2.ถ้าไม่มี locale ที่ต้องการ ให้ generate:
ตัวอย่างสำหรับ en_US.UTF-8:
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8
3.แก้ไฟล์ environment ของผู้ใช้ (เช่น ~/.bashrc หรือ ~/.profile)
teee@san:~$ export LC_CTYPE=UTF-8
teee@san:~$ export LC_CTYPE=en_US.utf8
teee@san:~$ source ~/.bashrc
teee@san:~$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE=”en_US.UTF-8″
LC_NUMERIC=”en_US.UTF-8″
LC_TIME=”en_US.UTF-8″
4. Logout/Login อีกครั้ง
การอัปเกรด จาก Debian 12.11 (Bookworm) → Debian 13.0 (Trixie)
การอัปเกรด จาก Debian 12.11 (Bookworm) → Debian 13.0 (Trixie) ทำได้แบบ in-place upgrade (ไม่ต้องลงใหม่)
ขั้นตอนการอัปเกรด Debian 12 → 13
⚠️ ข้อควรระวัง
• ควร backup ข้อมูลและ config สำคัญ (เช่น /etc, /home, ฐานข้อมูล ฯลฯ) ก่อน
• ทำการอัปเกรดผ่าน SSH + tmux/screen เผื่อเน็ตหลุดจะได้ไม่พัง
• ต้องมี free space ใน / และ /boot พอสมควร
1. อัปเดต Debian 12 (Bookworm) ให้ล่าสุดก่อน
sudo apt update
sudo apt upgrade
sudo apt full-upgrade
sudo apt –purge autoremove
ตรวจสอบเวอร์ชัน
root@san:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
ควรขึ้นว่า Debian GNU/Linux 12.11 (bookworm)
2. เปลี่ยน APT sources ไปที่ Trixie
เปิดไฟล์ /etc/apt/sources.list ด้วย editor (เช่น nano)
sudo nano /etc/apt/sources.list
แล้วเปลี่ยนคำว่า bookworm → trixie
#deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
#deb http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
#deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
deb http://deb.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware
3. อัปเดตแพ็กเกจให้เห็น repo ใหม่
sudo apt update
4. ทำ minimal upgrade
sudo apt upgrade –without-new-pkgs
5. อัปเกรดเต็มระบบเป็น Debian 13
sudo apt full-upgrade
ตรงนี้จะใช้เวลานาน และอาจมี prompt ถามว่าจะเก็บไฟล์ config เดิมหรือใช้ไฟล์ใหม่ (แนะนำกด N เพื่อเก็บ config เดิม เว้นแต่คุณอยาก reset)
6. ล้างของเก่า
sudo apt –purge autoremove
7. รีบูตเครื่อง
sudo reboot
8. ตรวจสอบเวอร์ชันหลังอัปเกรด
lsb_release -a
ควรขึ้นว่า
root@san:/home/teee# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 13 (trixie)
Release: 13
Codename: trixie
แต่ถ้าขึ้น Error
Description: Debian GNU/Linux 13.0 (trixie)
Errors were encountered while processing:
ca-certificates
php-composer-ca-bundle
python3-certifi
python3-requests
freeradius-config
python3-pip
python3-httplib2
ca-certificates-java
python3-reportbug
liblwp-protocol-https-perl
libwww-perl
python3-pip-whl
reportbug
E: Sub-process /usr/bin/dpkg returned an error code (1)
ปัญหานี้เจอบ่อยตอน major upgrade ของ Debian → สาเหตุคือ dependency chain เปลี่ยน / มีไฟล์ค้าง / แพ็กเกจไม่ compatible แบบตรงๆ
root@san:~# dpkg –configure -a
Setting up ca-certificates (20250419) …
Updating certificates in /etc/ssl/certs…
0 added, 0 removed; done.
Setting up php-composer-ca-bundle (1.5.6-1) …
Setting up python3-certifi (2025.1.31+ds-1) …
Setting up python3-requests (2.32.3+dfsg-5) …
Setting up freeradius-config (3.2.7+dfsg-1) …
Installing new version of config file /etc/freeradius/3.0/certs/Makefile …
Installing new version of config file /etc/freeradius/3.0/clients.conf …
Installing new version of config file /etc/freeradius/3.0/mods-available/date …
Installing new version of config file /etc/freeradius/3.0/mods-available/detail …
Installing new version of config file /etc/freeradius/3.0/mods-available/eap …
Installing new version of config file /etc/freeradius/3.0/mods-available/json …
Installing new version of config file /etc/freeradius/3.0/mods-available/ldap …
Installing new version of config file /etc/freeradius/3.0/mods-available/ldap_google …
Installing new version of config file /etc/freeradius/3.0/mods-available/linelog …
Installing new version of config file /etc/freeradius/3.0/mods-available/mschap …
Installing new version of config file /etc/freeradius/3.0/mods-available/python3 …
Installing new version of config file /etc/freeradius/3.0/mods-available/radutmp …
Installing new version of config file /etc/freeradius/3.0/mods-available/rest …
Installing new version of config file /etc/freeradius/3.0/mods-available/smsotp …
Configuration file ‘/etc/freeradius/3.0/mods-available/sql’
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer’s version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** sql (Y/I/N/O/D/Z) [default=N] ? N
Configuration file ‘/etc/freeradius/3.0/radiusd.conf’
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer’s version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** radiusd.conf (Y/I/N/O/D/Z) [default=N] ? N
root@san:~# apt -f install
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
The following packages were automatically installed and are no longer required:
icu-devtools libicu-dev libnsl-dev libpthread-stubs0-dev libsub-override-perl libtirpc-dev node-busboy node-end-of-stream node-pump python3-httplib2 python3-pycurl python3-pyparsing
python3-pysimplesoap sgml-base
Use ‘apt autoremove’ to remove them.
0 upgraded, 0 newly installed, 0 to remove and 419 not upgraded.
root@san:~# apt autoremove
root@san:~# sudo apt update
root@san:~# apt list –upgradable
root@san:~# apt upgrade
Aug 18 14:07:33 san apachectl[1755]: apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/perl.load: Cannot load /usr/lib/apache2/module>
Aug 18 14:07:33 san apachectl[1752]: Action ‘start’ failed.
Aug 18 14:07:33 san apachectl[1752]: The Apache error log may have more information
อันนี้เป็น error ของ Apache2 หลังอัปเกรด Debian → module perl โหลดไม่ได้
ซึ่งหมายถึง ไฟล์ mod_perl.so หายไป หรือไม่ compatible กับ Apache เวอร์ชันใหม่ (เพราะ Debian 13 ใช้ Apache 2.4.62 ขึ้นไป → mod_perl เดิมของ Debian 12 ไม่ใช้ได้แล้ว)
วิธีแก้ปัญหา
1. เช็คว่ามี mod_perl package ติดตั้งอยู่หรือไม่
dpkg -l | grep libapache2-mod-perl2
•ถ้าไม่เจอ → ต้องติดตั้งใหม่
•ถ้ามีแต่ไฟล์ไม่อยู่ → ลอง reinstall
2. ติดตั้งหรือ reinstall mod_perl
sudo apt update
sudo apt install –reinstall libapache2-mod-perl2
3. ถ้ายังมี error → ปิดการโหลด perl module ไปก่อน
sudo a2dismod perl
sudo systemctl restart apache2
Apache จะรันได้ตามปกติ แต่จะ ไม่มี mod_perl (ใช้ CGI/Perl script ไม่ได้)
4. ถ้าต้องการ mod_perl จริง ๆ
•ตรวจสอบ path ของ module:
ls -l /usr/lib/apache2/modules/ | grep perl
•แล้วแก้ไขไฟล์ /etc/apache2/mods-enabled/perl.load ให้ตรงกับไฟล์ที่มีอยู่จริง เช่น:
Apache
LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so
(บางเวอร์ชันอาจจะชื่อ mod_perl.c หรือ path ย้าย)
5. Restart Apache อีกครั้ง
sudo systemctl restart apache2
sudo systemctl status apache2
👉 คำถามคือ: ยังต้องใช้ Perl บน Apache อยู่ไหม (เช่นรัน CGI/Perl script)?
•ถ้าไม่ใช้ → แค่ a2dismod perl แล้ว Apache จะกลับมาปกติ
•ถ้ายังใช้ → ต้องลง libapache2-mod-perl2 ใหม่ให้ตรงกับ Debian 13
✅ เสร็จแล้ว คุณจะได้ Debian 13.0 stable (Trixie)
วิธีเพิ่ม Harddisk ให้กับ Linux Guest บน VmWare
วิธีเพิ่ม Harddisk ให้กับ Linux Guest บน VmWare
> Vmware Guest และได้ Edit เพื่อเพิ่ม Harddisk

และตรวจสอบ Harddisk ที่เพิ่มเข้าไปใหม่เจอในระบบหรือไม่ด้วยคำสั่ง lsblk
หากไม่เจอ Harddisk ใหม่ที่เพิ่มเข้ามาให้ใช้คำสั่ง
for host in /sys/class/scsi_host/host*; do
echo “- – -” | sudo tee $host/scan
done

และตรวจสอบใหม่ก็จะเจอ Harddisk ใหม่ที่เพิ่มเข้ามา

นำไปใช้งาน สร้าง Physical Volume (PV) ใหม่
root@oracle:/home/teee# pvcreate /dev/sdb
Physical volume “/dev/sdb” successfully created.
ขยาย Volume Group (VG)

ตรวจสอบก่อนว่าใช้ File System ชนิดไหน

resize2fs(สำหรับ ext4) หรือ xfs_growfs(สำหรับ xfs)
-
ext4: resize2fs สามารถทำแบบ online ได้ ถ้า mount อยู่แล้ว


Linux ค้นหาไฟล์ที่เก่ากว่า 30 วันให้ลบออก
ใน Linux สามารถใช้คำสั่ง find เพื่อค้นหาและลบไฟล์ที่ เก่ากว่า 1 เดือน ได้ตามนี้
คำสั่ง:-
#find /path/to/folder -type f -mtime +30 -exec rm -f {} \;
/path/to/folder = โฟลเดอร์ที่คุณต้องการค้นหา (เช่น /var/log หรือ /mnt/backup)
-type f = เลือกเฉพาะไฟล์ (ไม่รวมโฟลเดอร์)
-mtime +30 = ไฟล์ที่ ถูกแก้ไขครั้งสุดท้ายมากกว่า 30 วัน (ประมาณ 1 เดือน)
-exec rm -f {} \; = ลบไฟล์ที่เจอทันที
ถ้าต้องการแค่ดูรายการไฟล์ (ไม่ลบ):
#find /path/to/folder -type f -mtime +30
Xsession: unable to start x session
Xsession: unable to start x session — “no /home/teee/.xsession” file no session manager , no windows manager ,and no terminal emulator found, abourting
ข้อความผิดพลาดนี้บอกว่า X ไม่สามารถเริ่มเซสชันได้เพราะ:
-
ไม่มีไฟล์
~/.xsession -
ไม่มี session manager
-
ไม่มี window manager
-
ไม่มี terminal emulator
สาเหตุที่เป็นไปได้:
-
XFCE ยังไม่ได้ติดตั้งครบ
-
ไม่มี display manager หรือถูกตั้งค่าผิด
-
X11 พยายามเริ่มต้นจาก
.xsessionแต่ไม่มีการกำหนดค่า
วิธีแก้ไข
วิธีที่ 1: ตรวจสอบและติดตั้ง XFCE พร้อม X11 อย่างถูกต้อง
sudo apt update
sudo apt install xfce4 xfce4-goodies xorg lightdm
ระหว่างการติดตั้ง ถ้ามีคำถามเรื่อง Display Manager ให้เลือก lightdm
วิธีที่ 2: ตรวจสอบว่ามี session ของ XFCE ใน /usr/share/xsessions
ls /usr/share/xsessions
ควรเห็นไฟล์ชื่อประมาณ:
-
xfce.desktop
วิธีที่ 3:ตรวจสอบว่าติดตั้ง terminal emulator ด้วย
เช่น xfce4-terminal หรือ xterm:
sudo apt install xfce4-terminal xterm
เสร็จแล้วลอง Reboot ดู
Debian แก้ไขคำสั่งบูต GRUB ชั่วคราวเพื่อเข้าผ่าน shell
เลือกบรรทัดแรก (Debian GNU/Linux) แล้วกด e เพื่อ “edit”

หาบรรทัดที่ขึ้นต้นว่า:
linux /boot/vmlinuz-… root=UUID=… ro quiet
ลบ quiet ออก และ เพิ่ม:
linux /boot/vmlinuz-… root=UUID=… ro systemd.unit=multi-user.target

กด Ctrl + X หรือ F10 เพื่อบูตด้วยค่าที่คุณแก้ไข
Debian เปิดเครื่องเจอแต่ loopback interface
อาจเป็นไปได้ว่า interface จะ down อยู่ ให้ใช้คำสั่งครวจสอบ
#ip link show
#ip link set enp0s3 up
#dhclient enp0s3