温馨提示×

ifconfig是什么命令

小樊
49
2026-07-31 11:59:52
栏目: 编程语言

ifconfiginterface configuration 的缩写)是一个用于查看和配置网络接口的命令行工具,常见于 Linux / Unix / macOS 系统。


一、ifconfig 是做什么的?

ifconfig 主要用来:

  • 查看网络接口信息(IP 地址、MAC 地址、子网掩码等)
  • 启用 / 禁用网卡
  • 配置 IP 地址、子网掩码、广播地址
  • 设置 MTU、MAC 地址(部分系统)

二、常见用法示例

1️⃣ 查看所有网络接口

ifconfig

或(更详细)

ifconfig -a

输出示例:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>
      inet 192.168.1.100  netmask 255.255.255.0
      ether 00:11:22:33:44:55

2️⃣ 查看指定网卡

ifconfig eth0

3️⃣ 启用网卡

sudo ifconfig eth0 up

4️⃣ 禁用网卡

sudo ifconfig eth0 down

5️⃣ 设置 IP 地址

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

6️⃣ 修改 MAC 地址(部分系统)

sudo ifconfig eth0 hw ether 00:11:22:33:44:66

三、ifconfig 的现状(重要)

⚠️ ifconfig 已被逐步淘汰

  • 在现代 Linux 发行版中,ifconfig 属于 net-tools
  • 官方推荐使用 iproute2 中的 ip 命令

对应关系

ifconfig ip 命令
ifconfig ip addr
ifconfig eth0 up ip link set eth0 up
ifconfig eth0 192.168.1.100 ip addr add 192.168.1.100/24 dev eth0

四、ifconfig 不存在怎么办?

Ubuntu / Debian

sudo apt install net-tools

CentOS / RHEL

sudo yum install net-tools

五、在 Windows 中?

Windows 没有 ifconfig,对应的是:

ipconfig

(注意是 ipconfig,不是 ifconfig)


六、总结一句话

ifconfig 是 Linux/Unix 下查看和配置网络接口的传统命令,但现在更推荐使用 ip 命令。

如果你愿意,我可以帮你对比 ifconfigip 命令,或者结合你当前的系统(Ubuntu / CentOS / macOS)给你具体示例。

0