Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การแก้ไขปัญหา >> การบำรุงรักษาคอมพิวเตอร์

วิธีเปลี่ยน MAC Address บน Linux

การแก้ไข MAC Address ของระบบ ให้คุณปลอมแปลงเป็นอุปกรณ์อื่นในเครือข่ายเดียวกัน วิธีนี้เรียกว่า MAC Spoofing รับแพ็กเก็ตข้อมูลที่ตั้งใจส่งไปอุปกรณ์อื่น

บน Linux มี Tool เยอะมากสำหรับเปลี่ยน MAC Address แตหา Utility ที่น่าเชื่อถือ/เสถียร/ทำงานดี ยาก เพราะตัวเลือกเยอะเกินไป

จบบทความนี้ คุณจะเข้าใจ MAC Address แบบสั้น และวิธี Spoof MAC Address บน Linux

MAC Address คืออะไร?

MAC Address (Media Access Control Address) = รหัสเฉพาะตัวแบบ Hexadecimal ระบุอุปกรณ์บนเครือข่าย เรียกอีกอย่างว่า "Physical Address" เพราะฝังอยู่ใน Network Interface Card (NIC)

รูปแบบ MAC Address:

55:de:bc:7d:45:df

แต่ละอุปกรณ์ได้ MAC Address เฉพาะตัวตอนผลิต เพราะ MAC Address จึงระบุอุปกรณ์ล้านๆ บนอินเทอร์เน็ตได้อย่างไม่ซ้ำกัน

ใน OSI Model MAC Address ทำหน้าที่ส่งข้อมูลไปอุปกรณ์ที่ถูกต้องใน Data Link Layer

เปลี่ยน MAC Address บน Linux

เหตุผลเยอะที่อยากเปลี่ยน MAC Address: หลีกเลี่ยงข้อจำกัดความปลอดภัยบนเครือข่าย, หรือปลอมเป็นอุปกรณ์อื่นจับแพ็กเก็ต ไม่ว่าจะเป็นเหตุผลไหน Linux Tools ครอบคลุม

ใช้ macchanger

macchanger = Terminal-based Linux Utility ให้เปลี่ยน MAC Address เริ่มต้นของอุปกรณ์

ติดตั้ง Debian/Ubuntu:

sudo apt install macchanger

Fedora, CentOS, RHEL-based:

sudo dnf install macchanger
sudo yum install macchanger

Arch Linux:

sudo pacman -S macchanger

จะมี Prompt ถาม: เปลี่ยน MAC Address ทุกครั้งที่ Restart Network Device (Ethernet/Wi-Fi) เลือก No Enter

ก่อนเริ่ม ตรวจสอบ Network Interface Names: พิมพ์

ip addr
วิธีเปลี่ยน MAC Address บน Linux

Output: Interface 名สำหรับ Ethernet คือ eth0 Wi-Fi จะเป็น wlan0 หรือ wlp3s0

แยกได้ง่าย: Interface เริ่มต้น w = Wi-Fi, เริ่มต้น e = Ethernet

เช็ค MAC Address ปัจจุบัน:

macchanger -s interface

interface = ชื่อ Network Interface ที่ต้องการดู

วิธีเปลี่ยน MAC Address บน Linux

กำหนด MAC Address แบบสุ่ม: ใช้ Flag -r

macchanger -r interface

ตัวอย่าง เปลี่ยน eth0:

sudo macchanger -r eth0

macchanger จะแสดง Original Address และ Current (Modified) Address

วิธีเปลี่ยน MAC Address บน Linux

กำหนด MAC Address เอง: ใช้ Flag -m

sudo macchanger -m custom-address interface

custom-address = MAC Address ใหม่, interface = ชื่อ Interface

ตัวอย่าง กำหนดให้ eth0:

sudo macchanger -m 44:ee:bc:6c:76:ba eth0

macchanger จดจำ Original MAC ให้ รีเซ็ตกลับค่าเดิมง่ายด้วย Flag -p:

sudo macchanger -p eth0

ใช้คำสั่ง ip และ ifconfig

macchanger ใช้ง่าย เหมาะมือใหม่ แตผู้ใช้ขั้นสูงที่ต้องการควบคุมมากขึ้น อาจชอบคำสั่ง ip

สำคัญ: บันทึก Original MAC Address ไว้ก่อนแก้ไข เพราะหลังเปลี่ยนด้วยคำสั่งด้านล่าง ไม่มีตัวเลือก Revert อัตโนมัติ ต้องเปลี่ยนกลับด้วยตนเอง

ก่อนเปลี่ยน MAC ด้วย ip ต้องปิด Network Interface ก่อน:

sudo ip link set dev eth0 down

เปลี่ยน MAC เป็น Custom Address:

sudo ip link set dev eth0 address 44:ee:bc:6c:76:ba

Restart Interface:

sudo ip link set dev eth0 up

เช็คว่าทำงาน: พิมพ์ ip addr ใน Terminal

วิธีเปลี่ยน MAC Address บน Linux

วิธีอีกอย่าง: ifconfig (Interface Config) Utility มาตรฐาน Linux จัดการ Network Interfaces

เหมือน ip ต้องปิด Interface ก่อน:

sudo ifconfig eth0 down

กำหนด Custom MAC:

sudo ifconfig eth0 hw ether 44:ee:bc:6c:76:ba

Restart Interface:

sudo ifconfig eth0 up

เปลี่ยน MAC ของ Wireless Interface (wlan0): แทน eth0 ด้วยชื่อ Wireless Interface

sudo ifconfig wlan0 hw ether 44:ee:bc:6c:76:ba

เหมือนเทคนิค Cybersecurity อื่นๆ มีเส้นบางระหว่าง Legal/Illegal ขึ้นอยู่กับ Use Case

วัตถุประสงค์การศึกษา/เรียนรู้? ถูกต้อง (แต่แค่บนเครือข่ายของตัวเอง) จับแพ็กเก็ต/ข้าม Security Protocols บนเครือข่ายอื่น? ไม่แนะนำ

Windows และ Mac ก็ View/Modify MAC Address ได้ เหมือนกัน แตกต่างแค่ Interface: Linux ชอบ Command-line Windows/Mac ชอบ GUI