หน้า 1 จากทั้งหมด 1

เทคนิคการเปลี่ยน RasPBX ให้ใช้ IP Address แบบ Static

โพสต์โพสต์แล้ว: 19 ก.ย. 2015 14:37
โดย nuiz
ระหว่างการติดตั้ง RasPBX นั้น ตัวติดตั้งเซ็ต IP ให้รับมาจาก DHCP Server ซึ่งเราสามารถเช็ค IP ที่ได้รับได้ทั้งจากบน DHCP Server และตัวเครื่อง RasPBX โดยตรง โดยรันคำสั่ง
โค้ด: เลือกทั้งหมด
ifconfig

ผลลัพธ์
โค้ด: เลือกทั้งหมด
eth0      Link encap:Ethernet  HWaddr b8:27:eb:27:46:20 
          inet addr:192.168.130.149  Bcast:192.168.130.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fe27:4620/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:29638 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12003 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:30745829 (29.3 MiB)  TX bytes:1072775 (1.0 MiB)


ซึ่งจากข้อมูลตัวอย่าง เรารู้ไอพีของเครื่องคือ 192.168.130.149

แต่ในการใช้งานจริงคงไม่เหมาะแน่ๆครับที่เราจะให้ RasPBX รับไอพีแบบ Dynamic เพราะมีโอกาสที่ไอพีจะเปลี่ยนได้ เราควรจะเซ็ตไอพีแบบ Static จะได้แน่ใจว่าไอพีไม่เปลี่ยนชัวร์ (ยกเว้นใครแอบบมาเปลี่ยนของเรา) วิธีการเซ็ตไอพีของ RasPBX แบบ Static มีดังต่อไปนี้ครับ

** เนื่องจาก RasPBX ใช้ระบบปฏิบัติการ Debian ดังนั้นการเปลี่ยนไอพีจึงใช้วิธีการเดียวกันครับ **

1. เปิดไฟล์ /etc/network/interfaces
คำสั่ง
โค้ด: เลือกทั้งหมด
nano /etc/network/interfaces

ข้อมูลดั้งเดิมในไฟล์นี้ครับ
โค้ด: เลือกทั้งหมด
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

auto lo
auto eth0

iface lo inet loopback
iface eth0 inet dhcp


ให้เราทำดังนี้
ใส่เครื่องหมาย # ไว้หน้าบรรทัด iface eth0 inet dhcp
และเพิ่มบรรทัดต่อไปนี้ สมมติว่าจะใช้ ip 192.168.130.50 subnet mask 255.255.255.0 default gateway 192.168.130.1 และ dns 192.168.130.1
allow-hotplug eth0
iface eth0 inet static
address 192.168.130.50
netmask 255.255.255.0
gateway 192.168.130.1
dns-nameservers 192.168.130.1

ดังนั้นในไฟล์ /etc/network/interfaces จะมีข้อมูลเป็นแบบนี้ครับ
โค้ด: เลือกทั้งหมด
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

auto lo
auto eth0
allow-hotplug eth0
iface lo inet loopback
#iface eth0 inet dhcp

iface eth0 inet static
address 192.168.130.50
netmask 255.255.255.0
gateway 192.168.130.1
dns-nameservers 192.168.130.1


2. บันทึกไฟล์

3. รีสตาร์ท network
คำสั่ง
โค้ด: เลือกทั้งหมด
service networking restart


4. ตรวจสอบ
คำสั่ง
โค้ด: เลือกทั้งหมด
ifconfig

ผลลัพธ์
โค้ด: เลือกทั้งหมด
eth0      Link encap:Ethernet  HWaddr b8:27:eb:27:46:20 
          inet addr:192.168.130.50  Bcast:192.168.130.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fe27:4620/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:31364 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12327 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:30869314 (29.4 MiB)  TX bytes:1120197 (1.0 MiB)