温馨提示×

ifconfig在Debian怎么用

小樊
36
2026-07-21 21:12:38
栏目: 智能运维

ifconfigDebian 里用法和在其他 Linux 发行版基本一致,但需要注意一个常见问题:新版 Debian 默认可能没有安装它。下面我按实际使用场景给你说明。


一、为什么 ifconfig 可能用不了?

从 Debian 9(Stretch)及以后版本开始,ifconfig 被逐步弃用,官方推荐使用 ip 命令。
ifconfig 属于 net-tools 软件包,Debian 默认 不再预装

检查是否安装:

which ifconfig

如果没输出,说明没装。


二、安装 ifconfig(如确实需要)

sudo apt update
sudo apt install net-tools

安装完成后即可使用。


三、ifconfig 常用用法

1️⃣ 查看所有网络接口

ifconfig

或(不解析 DNS,速度更快):

ifconfig -a

示例输出:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
      inet 192.168.1.100  netmask 255.255.255.0
      inet6 fe80::20c:29ff:fe12:3456  prefixlen 64
      ether 00:0c:29:12:34:56  txqueuelen 1000

2️⃣ 查看指定网卡

ifconfig eth0

3️⃣ 启用 / 禁用网卡

sudo ifconfig eth0 up
sudo ifconfig eth0 down

⚠️ 注意:只是临时生效,重启后失效。


4️⃣ 设置 IP 地址(临时)

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

5️⃣ 添加 / 删除辅助 IP

sudo ifconfig eth0:1 192.168.1.101
sudo ifconfig eth0:1 down

6️⃣ 修改 MAC 地址(临时)

sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up

四、推荐:用 ip 命令替代(现代做法)

Debian 官方更推荐:

ip addr          # 查看 IP
ip link          # 查看网卡状态
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0

五、永久配置网络(Debian)

ifconfig 不能保存配置,永久配置用:

传统方式(Debian 10 及以前常见)

编辑:

sudo nano /etc/network/interfaces

示例:

auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1

重启网络:

sudo systemctl restart networking

六、总结建议

临时查看 / 调试ifconfig 可以
新系统 / 脚本 / 长期管理 → 用 ip
ifconfig 不再被维护


如果你愿意,我可以:

  • 帮你对比 ifconfig vs ip
  • 给你 Debian 12 的具体网络配置示例
  • 排查网卡无法启动 / 没有 IP 的问题

0