温馨提示×

linux ifconfig是什么命令

小樊
31
2026-09-10 22:35:31
栏目: 智能运维

在 Linux 系统中,ifconfig 是一个用于配置和查看网络接口信息的命令,全称是 interface config(接口配置)。


一、ifconfig 是做什么的?

ifconfig 主要用来:

  • 查看网卡(网络接口)状态
  • 查看 IP 地址、子网掩码、MAC 地址
  • 启用 / 禁用网卡
  • 配置 IP 地址(临时生效)

二、常见用法示例

1️⃣ 查看所有网络接口信息

ifconfig

ifconfig -a

输出内容包括:

  • inet:IPv4 地址
  • netmask:子网掩码
  • ether:MAC 地址
  • RX/TX:收发数据包统计

2️⃣ 查看指定网卡

ifconfig eth0

3️⃣ 启用网卡

ifconfig eth0 up

4️⃣ 禁用网卡

ifconfig eth0 down

5️⃣ 临时配置 IP 地址

ifconfig eth0 192.168.1.100 netmask 255.255.255.0

⚠️ 重启后失效(仅临时)


三、ifconfig 的现状(很重要)

  • ifconfig 属于 net-tools 工具包
  • 在新版 Linux(如 CentOS 7+、Ubuntu 18+)中:
    • 默认可能没安装
    • 已被 ip 命令取代

查看 IP 的推荐新命令

ip addr

ip a

启用 / 禁用网卡

ip link set eth0 up
ip link set eth0 down

四、如果提示 command not found

安装方法:

# CentOS / RHEL
yum install net-tools

# Ubuntu / Debian
apt install net-tools

五、总结一句话

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

如果你愿意,我也可以帮你对比 ifconfigip 命令,或者讲怎么永久配置 IP。

0