ตั้งค่า IP Addess ของ RPi ให้เป็น static IP Addess

สอบถามเรื่องทั่วไป กับ การใช้คอมพิวเตอร์โดยทั่วไป แนะนำข่าวสารไวรัสคอม เทคนิคเล็กน้อยๆ กับ การใช้ คอมพิวเตอร์ ให้มีประสิทธิภาพมากที่สุด ฝากคำถามไว้ได้นะค่ะ

Moderator: mindphp, ผู้ดูแลกระดาน

bellzeed
PHP Sr. Member
PHP Sr. Member
โพสต์: 82
ลงทะเบียนเมื่อ: 20/06/2017 2:03 pm

ตั้งค่า IP Addess ของ RPi ให้เป็น static IP Addess

โพสต์ที่ยังไม่ได้อ่าน โดย bellzeed »

กรณีที่เราอยากตั้งค่า IP addressของ RPi ให้เป็น static IP address นะครับ มาเริ่มกันเลย

1. Terminal พิมพ์คำสั่ง

โค้ด: เลือกทั้งหมด

sudo ifconfig
มันจะแสดงข้อมูล Network ปัจจุบันที่ถูกตั้งไว้ครับ

2. จากนั้นใช้คำสั่ง

โค้ด: เลือกทั้งหมด

sudo route -n
เพื่อดูข้อมูลของเราเตอร์ของเรา เพื่อจำค่า Gateway
3. เปิดไฟล์ /etc/dhcpcd.conf ขึ้นมาใช้คำสั่ง

โค้ด: เลือกทั้งหมด

sudo nano /etc/dhcpcd.conf
4.เลื่อนลงมาล่างสุดของโค้ดเพื่อเพิ่มบรรทัดใหม่เข้าไปดังตัวอย่าง

โค้ด: เลือกทั้งหมด

interface eth0
static ip_address=192.168.1.222/24
static routers=192.168.1.20
static domain_name_servers=192.168.1.20
interface = การกำหนดว่าจะกำหนด ip address ให้กับ network interface ไหน ถ้าเป็น Ethernet อย่างในตัวอย่างก็กำหนดเป็น eth0 แต่ถ้าเป็น wireless ก็กำหนดเป็น wlan0
static ip_address = กำหนด IP address ที่เราต้องการ อย่าลืมเติม /24 ต่อท้ายด้วย
static routers = IP address ของ gateway อย่างเราใช้ที่บ้านก็ IP address เราเตอร์ที่บ้าน
static domain_name_servers = IP address ของ DNS เราใช้ที่บ้านก็ใช้ IP ของเราเตอร์ที่บ้าน
เสร็จแล้วก็กด ctrl+x แล้ว save โดยพิมพ์ y แล้ว Enter

เมื่อเสร็จแล้วให้เรา Restart 1 ครั้ง พิมพ์คำสั่ง

โค้ด: เลือกทั้งหมด

sudo reboot
หลังจาก restart แล้วเปิด Terminal ขึ้นมาอีกครั้งเพื่อเช็คดู IP Addess เท่านี้เราก็จะเห็น IP ที่เรากำหนดไว้ครับ

References
https://wiki.archlinux.org/index.php/dhcpcd
prakon
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 561
ลงทะเบียนเมื่อ: 02/07/2018 10:45 am

Re: ตั้งค่า IP Addess ของ RPi ให้เป็น static IP Addess

โพสต์ที่ยังไม่ได้อ่าน โดย prakon »

หลังจากที่ลองทำตามดูแล้ว พบว่ามีปํญหาอยู่เล็กน้อย สรุปได้ดังนี้คือ
1.ในหัวข้อที่ที่ 3 ที่เราเปิดไฟล์ dhcp มาใช้งาน ให้เรานั้นเช็คว่าในไฟล์มีข้อความตามนี้หรือไม่ ถ้ามีข้อความเกินมาให้ลบอออก(ข้อความที่เกินมาอาจมาจากกการconfigที่ผิดพลาดหรือมาจากจากตัวระบบเอง
static ip.png
static ip.png (70.38 KiB) Viewed 1649 times
และ
statci2.png
statci2.png (30.12 KiB) Viewed 1649 times
เมื่อเช็คเสร็จแล้วจึงค่อยใส่ข้อความในหัวข้อที่4 ลงไปด้านล่างสุด

ตัวอย่างที่ทำเสร็จแล้ว

โค้ด: เลือกทั้งหมด

 A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: facebook.com [Crawler] และบุคลทั่วไป 90