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

แก้ 'ifconfig: command not found' บน Linux - คู่มือด่วน

ผู้ใช้ Linux มักใช้คำสั่ง “ifconfig” เพื่อดูและเปลี่ยนแปลง network interface การใช้งานรวมถึงดู IP address, hardware address, MTU และอื่นๆ บางคนเจอ error “bash: /usr/sbin/ifconfig: No such file or directory” เกิดเมื่อ net-tools package ไม่ได้ติดตั้ง บางคนติดตั้งแล้วก็ยังไม่ได้

เข้าใจคำสั่ง ‘ifconfig’

ifconfig ย่อมาจาก “Interface configuration” รับผิดชอบ configure network interfaces เช่น Ethernet, wireless cards, virtual interfaces มีบทบาทสำคัญใน Linux เพราะแสดงข้อมูลจำเป็น เช่น IP address, netmask และ network terms อื่นๆ ที่ user สามารถปรับได้ สาเหตุ “Command ‘ifconfig’ not found”

สาเหตุหลักคือระบบไม่มี net-tools package ที่มี ifconfig utility ดู error:

ifconfig command not found

คู่มือทีละขั้นตอนแก้ ‘ifconfig’ error

ทุก Linux user ควรรู้ว่า คำสั่ง “ip” ที่ทรงพลังกว่าและมีฟีเจอร์มากกว่า ได้แทนที่ “ifconfig” แล้ว net-tools toolkit ที่มี utility นี้ อาจไม่ได้ติดตั้งมาพร้อมกับ distro เพราะ deprecated ดังนั้น error “bash: /usr/sbin/ifconfig: No such file or directory” จึงเกิดขึ้น

ขั้นตอน 1: ติดตั้ง net-tools

เพื่อใช้ “ifconfig” ต้องติดตั้ง net-tools toolkit:

$ sudo apt install net-tools

Installing net-tools
คำสั่งนี้ใช้ได้กับ Debian และ Ubuntu ถ้าใช้ distro อื่น ใช้คำสั่ง:

$ sudo yum install net-tools #For RHEL or CentOS
$ sudo dnf install net-tools #For Fedora 22+
$ sudo zypper install net-tools #For openSUSE

ขั้นตอน 2: รันคำสั่ง ifconfig

หลังติดตั้ง net-tools ลองรัน ifconfig ใหม่ ควรทำงานได้ปกติ

$ ifconfig

ifconfig command
ถ้ายังไม่ได้ ไปขั้นตอนที่ 3

ขั้นตอน 3: เพิ่ม /sbin เข้า PATH variable ของระบบ

หลังติดตั้ง net-tools ถ้า “ifconfig” ยังไม่ทำงาน ควรเพิ่ม ‘/sbin’ เข้า PATH variable ของระบบ เพราะ ‘/sbin’ ไม่อยู่ใน PATH โดย default รันคำสั่ง:

$ export PATH="/sbin:/usr/sbin:${PATH}"

Adding ‘/sbin’ to PATH variable
ต้องเพิ่มเพราะถ้าไม่เพิ่ม จะต้องพิมพ์ full path ของ “ifconfig” ทุกครั้งที่รัน ซึ่งยุ่งยาก สั่งเสร็จ restart ระบบเพื่อให้การเปลี่ยนแปลงมีผล

ทำไม ifconfig ถูก deprecated?

บาง developer กล่าวว่า deprecated เพราะไม่มี development มา 20 ปี สาเหตุคือไม่รองรับ networking technologies ใหม่ และขาด versatility/flexibility เทียบกับเครื่องมืออื่น แนะนำให้เปลี่ยนใช้คำสั่ง “ip” ซึ่ง developer ถือว่า versatile และ flexible กว่า ifconfig และมี options มากกว่า
Syntax ของ “ip” command:

ip [ OPTIONS ] OBJECT { COMMAND | help }

ดู help ของ “ip command” ด้วย man page หรือ:

$ ip help

ip help command

คุณสามารถแก้ error “bash: /usr/sbin/ifconfig: No such file or directory” ได้ แต่เพราะมันคำสั่งเก่า เราไม่แนะนำให้ใช้ แม้หลายคนยังใช้อยู่ แต่ 왜เลือกน้อยกว่าที่ดีที่สุด?

ABOUT THE AUTHOR

แก้  ifconfig: command not found  บน Linux - คู่มือด่วน

Kevin Arrows

Kevin Arrows เป็นผู้เชี่ยวชาญด้านเทคโนโลยีที่มีประสบการณ์มากกว่า 10 ปี ได้รับการรับรอง Microsoft Certified Technology Specialist (MCTS) มีความหลงใหลในการอัปเดตเทคโนโลยีล่าสุด เขียนบทความเกี่ยวกับหัวข้อเทคโนโลยีกว้างขวาง แสดงความเชี่ยวชาญในด้านการพัฒนาซอฟต์แวร์ ความปลอดภัยไซเบอร์ และ Cloud Computing ได้รับการยอมรับและเคารพจากเพื่อนร่วมงาน สามารถอธิบายแนวคิดทางเทคนิคที่ซับซ้อนได้อย่างชัดเจนและกระชับ