การตั้งค่า Static IP ด้วย Netplan บน Ubuntu Server 25.10

การตั้งค่า Static IP ด้วย Netplan บน Ubuntu Server 25.10

บน Ubuntu Server รุ่นใหม่ (18.04 ขึ้นไปจนถึง 25.10) ระบบเครือข่ายจะถูกจัดการด้วยเครื่องมือชื่อ Netplan ซึ่งใช้ไฟล์รูปแบบ YAML (.yaml) ในการกำหนดค่าต่าง ๆ เช่น

  • IP Address
  • Gateway
  • DNS Server
  • DHCP

การตั้งค่า Static IP เป็นสิ่งสำคัญสำหรับงาน Server Administration เช่น

  • Web Server
  • Database Server
  • Docker Host
  • Monitoring Server
  • IoT Gateway

เพราะบริการเหล่านี้ต้องมี IP Address คงที่ เพื่อให้เครื่องอื่นเชื่อมต่อได้เสมอ

บทความนี้จะแนะนำการตั้งค่า Static IP ด้วย Netplan บน Ubuntu Server 25.10 แบบ Step-by-Step


พื้นฐานที่ต้องมี (Prerequisites)

ก่อนเริ่มควรมีข้อมูลดังนี้

รายการ ตัวอย่าง
Network Interface ens33
IP Address 192.168.1.50
Subnet /24
Gateway 192.168.1.1
DNS 8.8.8.8, 1.1.1.1

ตรวจสอบ ชื่อ Network Interface

ip a
ตัวอย่างผลลัพธ์
 
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP>
แสดงว่า interface ที่ใช้งานคือ
ens33
 

1. ตรวจสอบไฟล์ Netplan

ไฟล์ configuration จะอยู่ที่

/etc/netplan/
 

ตรวจสอบไฟล์

ls /etc/netplan
 

ตัวอย่าง

00-installer-config.yaml
 

2. แก้ไขไฟล์ Netplan

เปิดไฟล์ด้วย nano

sudo nano /etc/netplan/00-installer-config.yaml
 

ตัวอย่างไฟล์สำหรับ Static IP

network:
   version: 2
   renderer: networkd
   ethernets:
       ens33:
       dhcp4: no
       addresses:
          – 192.168.1.50/24
       routes:
          – to: default
              via: 192.168.1.1
       nameservers:
       addresses:
            – 8.8.8.8
            – 1.1.1.1
 

อธิบายแต่ละส่วน

Parameter ความหมาย
network เริ่มต้น config
version เวอร์ชันของ Netplan
renderer ตัวจัดการ network (networkd สำหรับ server)
ethernets กำหนด interface
dhcp4 ปิด DHCP
addresses IP Address
routes Gateway
nameservers DNS

3. ตรวจสอบ Syntax ก่อน Apply 

ก่อนใช้งานควรตรวจสอบ configuration

sudo netplan try
ระบบจะทดสอบ config ใหม่ หากมีปัญหาจะ revert กลับ

4. Apply การตั้งค่า

เมื่อมั่นใจว่า config ถูกต้อง

sudo netplan apply
 

5. ตรวจสอบ IP ใหม่

ตรวจสอบ IP

ip a
 

หรือ

ip addr show ens33
 

ตัวอย่างผลลัพธ์

inet 192.168.1.50/24
 

6. ทดสอบ Network

ทดสอบ Internet

ping -c 4 google.com
 

หรือ

ping -c 4 8.8.8.8
 

ถ้า ping ได้ แสดงว่าการตั้งค่า Static IP สำเร็จ


ปัญหาที่พบบ่อย (Troubleshooting)

1. YAML indentation ผิด

ไฟล์ YAML ต้องเว้นวรรคให้ถูกต้อง

ตัวอย่างผิด

addresses:
– 192.168.1.50/24
 

ตัวอย่างถูก

addresses:
     – 192.168.1.50/24
 

2. Interface ผิด

ตรวจสอบด้วย

ip a
 

ชื่อ interface อาจเป็น

ens18
eth0
enp0s3
 

3. Gateway ไม่ถูก

ตรวจสอบ Gateway ของ network เช่น

192.168.1.1
 

สรุป

การตั้งค่า Static IP ด้วย Netplan บน Ubuntu Server 25.10 ทำได้ไม่ยาก โดยมีขั้นตอนหลักดังนี้

  1. ตรวจสอบ Network Interface (ip a)
  2. แก้ไขไฟล์ /etc/netplan/*.yaml
  3. กำหนด IP, Gateway, DNS
  4. ตรวจสอบ config ด้วย netplan try
  5. ใช้งานด้วย netplan apply

เมื่อเข้าใจ Netplan แล้ว การบริหารเครือข่ายบน Ubuntu Server จะง่ายขึ้นมาก และสามารถนำไปใช้กับงานจริง เช่น

  • Web Server
  • Docker Host
  • Kubernetes Node
  • IoT Server
  • Monitoring Server


Write by SysAdmin Knowledge
https://www.sysadmin.in.th
April 3, 2026