[เนื้อหา] Manage status of Network service บน Linux
เรามาดูการจัดการสถานะของ Network service ที่อยู่บน Linux -> starting, stoping, check status. ปกติแล้วใน server linux จะมี service รันอยู่ใน…
[เนื้อหา] Manage status of Network service บน Linux
เรามาดูการจัดการสถานะของ Network service ที่อยู่บน Linux -> starting, stoping, check status. ปกติแล้วใน server linux จะมี service รันอยู่ใน background เพื่อรองรับ incoming connection เช่น sshd, nginx, พวก db

Check status of network service
ดูการทำงานของ program ว่าพร้อมรับ incoming connection รึปล่าว มี tools ให้ใช้ 2 ตัว คือ ss และ netstat (ใช้ ss อันเดียวเลยก็ได้ เพราะ modern กว่า)
$ ss
การจะตรวจสอบดูว่า service พร้อมที่จะรับ incoming network สามารถใช้
$ sudo ss -ltunp
*ต้องการ sudo options:
- l คือ list ของ current listening for connection
- t คือ TCP connection
- u คือ UDP connection
- n คือ แสดงค่าเป็นตัวเลข -> จะได้ port number
- p คือ process อ่าน “ตรวจสอบ list ของ service ตัวไหนพร้อมรับ incoming connection แบบ tcp และ udp โดยแสดง port ด้วย”
ผล

จริงๆแล้ว มันสามารถลับตำแหน่งของ option ได้ เพื่อให้จำง่ายคือ tunlp
$ sudo ss -tunlp
ต่อไปเราเปิด program ที่รองรับ incoming connection เพิ่มขึ้น

แปลว่าตัวแปรแกรมเหล่านี้จะ listening incoming connection จาก คอมเครื่องอื่น
- maraidb daemon
แปลว่าถ้าเราเอา nginx มาต่อที่ 127.0.0.1 ที่ port 3306 ได้ เราก็จะสามารถคุยกับ db ได้ แล้ว other computer สามารถต่อกับ nginx ได้ ก็จะทำให้คุยกับ db ได้

- ssh daemon
0.0.0.0: 22 และ [::]:22 คือ listen ทุก IP ของ v4 และ v6 ให้สามารถคุยกับ sshd ได้
เช็คสถานะของ service ด้วย
$ sudo systemctl status [SERVICE_NAME]
eg.
$ sudo systemctl status ssh.service
$ sudo systemctl status mariadb.service
ลอง stop service maraidbd
$ sudo systemctl stop mariadb.service
และ เช็คสถานะ network service status ด้วย
$ sudo ss -ltunp
ก็จะเหลือแค่ sshd.

ถ้าจะปิดไม่ให้ service ถูก running ตอน start server
$ sudo systemctl disable [SERVICE_NAME]
eg.
$ sudo systemctl disable mariadb.service
หรือจะเปิดให้ service ถูก running ตอน start server
$ sudo systemctl enable [SERVICE_NAME]
eg.
$ sudo systemctl enable mariadb.service
และเปิดให้ service running
$ sudo systemctl start [SERVICE_NAME]
eg.
$ sudo systemctl start mariadb.service
เพิ่มคือ ตอนใช้คำสั่ง $ ss -ltunp เราจะได้ข้อมูล PID ของ service ด้วย

แปลว่าเราสามารถใช้คำสั่งดู process มาดูข้อมูลเพิ่มเติมได้
$ ps [PROCESS_ID]
eg.
$ ps 679

หรือจะเช็คไฟล์ที่เกี่ยวข้องกับ process id
$ sudo lsof -p 679

메타데이터
- post_id
- 6abcfe607cdc
- slug
- เนื้อหา-manage-status-of-network-service-บน-linux-6abcfe607cdc
- url
- https://medium.com/@astronut1911/%E0%B9%80%E0%B8%99%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%AB%E0%B8%B2-manage-status-of-network-service-%E0%B8%9A%E0%B8%99-linux-6abcfe607cdc
- canonical_url
- https://medium.com/@astronut1911/%E0%B9%80%E0%B8%99%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%AB%E0%B8%B2-manage-status-of-network-service-%E0%B8%9A%E0%B8%99-linux-6abcfe607cdc
- author_url
- https://medium.com/@astronut1911
- status
- ok
- fetched_at
- 2026-07-14 17:46:58