บทความนี้อธิบายวิธีตั้งค่า Additional IP Address บน AlmaLinux 9 + Plesk ด้วย NetworkManager Policy Routing เพื่อให้ IP เสริมสามารถใช้งานผ่าน Gateway ของตนเองได้อย่างถูกต้อง
วิธีตั้งค่า Additional IP บน AlmaLinux 9 + Plesk
กรุณาดำเนินการตามขั้นตอนดังต่อไปนี้
Step 1: Backup Network Configuration
สำรอง Network Configuration เดิมก่อนเริ่มแก้ไข
mkdir -p /root/network-backup-$(date +%F-%H%M)
cp -a /etc/NetworkManager/system-connections/* /root/network-backup-$(date +%F-%H%M)/ 2>/dev/nullStep 2: ตั้งค่า IPv4 ให้ eth1
กำหนด IP Address ให้กับ Interface eth1 และป้องกันไม่ให้ eth1 ถูกใช้เป็น Default Route หลัก
nmcli con modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 118.27.152.57/23 \
ipv4.never-default yesหาก Interface เดียวกันมี Additional IP Address มากกว่า 1 IP สามารถกำหนดหลาย IP ได้ เช่น ipv4.addresses "118.27.152.57/23,118.27.152.58/23,118.27.152.59/23" โดยทุก IP สามารถใช้งาน Gateway เดียวกันได้
Step 3: เพิ่ม Route สำหรับ eth1
เพิ่ม Route แยกสำหรับ IP เสริม เพื่อให้ใช้งาน Routing Table 102
nmcli con modify "Wired connection 1" \
+ipv4.routes "118.27.152.0/23 table=102" \
+ipv4.routes "0.0.0.0/0 118.27.152.1 table=102"Step 4: เพิ่ม Routing Rule
กำหนด Rule ให้ Traffic ที่มี Source IP เป็น 118.27.152.57 ใช้งาน Routing Table 102
nmcli con modify "Wired connection 1" \
+ipv4.routing-rules "priority 102 from 118.27.152.57/32 table 102"กรณีมี Additional IP Address มากกว่า 1 IP และใช้งานผ่าน Interface และ Gateway เดียวกัน สามารถใช้ Routing Table เดียวกันได้ เช่น table 102
โดยให้เพิ่ม Routing Rule แยกสำหรับแต่ละ Additional IP Address และกำหนดค่า Priority ไม่ให้ซ้ำกัน เช่น 102, 103, 104 ตามลำดับ
ตัวอย่าง
nmcli con modify "Wired connection 1" \
+ipv4.routing-rules "priority 102 from 118.27.152.57/32 table 102" \
+ipv4.routing-rules "priority 103 from 118.27.152.58/32 table 102" \
+ipv4.routing-rules "priority 104 from 118.27.152.59/32 table 102"
Step 5: Apply Network
ปิดและเปิด Connection ใหม่เพื่อให้ค่าที่ตั้งไว้มีผล
nmcli con down "Wired connection 1"
nmcli con up "Wired connection 1"Step 6: ทดสอบการออก Internet ด้วย IP eth1
ทดสอบว่า IP เสริมสามารถออก Internet ผ่าน Interface eth1 ได้ถูกต้อง
curl --interface 118.27.152.57 https://ifconfig.meผลลัพธ์ควรแสดงเป็น IP เสริมดังนี้
118.27.152.57Step 7: ให้ Plesk อ่าน IP ใหม่
สั่งให้ Plesk ตรวจสอบและอ่าน IP Address ใหม่จากระบบ
plesk bin ipmanage --rereadStep 8: Restart NetworkManager
Restart NetworkManager เพื่อให้ระบบโหลดค่า Network ล่าสุด
systemctl restart NetworkManagerตรวจสอบหลังตั้งค่า
หลังจากตั้งค่าเสร็จ สามารถตรวจสอบข้อมูล Network และ Routing ได้ด้วยคำสั่งต่อไปนี้
ip a show eth1
ip route
ip rule show
ip route show table 102สรุป หลังตั้งค่าเสร็จ eth0 จะยังเป็น Default Route หลักของ Server ส่วน Traffic ที่มี Source IP เป็น 118.27.152.57 จะออกผ่าน Gateway ของ eth1 คือ 118.27.152.1 หากมี Additional IP Address มากกว่า 1 IP และใช้งาน Gateway เดียวกัน สามารถใช้ Routing Table เดียวกันได้ โดยเพิ่ม Routing Rule แยกตามแต่ละ Source IP และกำหนด Priority ไม่ให้ซ้ำกัน