温馨提示×

Debian如何替代ifconfig

小樊
44
2026-08-20 14:00:33
栏目: 智能运维

在 Debian(以及大多数现代 Linux 发行版)中,ifconfig 已被 iproute2 套件取代,推荐使用 ip 命令。下面给你一个对照速查表,方便从 ifconfig 平滑迁移。


一、为什么不再用 ifconfig?

  • ifconfig 属于 net-tools,已多年不维护
  • ip 命令功能更强、更统一
  • Debian 10+ 默认通常不再预装 net-tools

二、常用 ifconfig → ip 对照

1️⃣ 查看网络接口

ifconfig

ifconfig

ip(推荐)

ip addr
# 或简写
ip a

只查看某个接口:

ip addr show eth0

2️⃣ 启用 / 禁用网卡

ifconfig

ifconfig eth0 up
ifconfig eth0 down

ip

ip link set eth0 up
ip link set eth0 down

3️⃣ 配置 IP 地址

ifconfig

ifconfig eth0 192.168.1.100 netmask 255.255.255.0

ip

ip addr add 192.168.1.100/24 dev eth0

删除 IP:

ip addr del 192.168.1.100/24 dev eth0

4️⃣ 查看路由表

ifconfig / route

route -n

ip

ip route

添加默认网关:

ip route add default via 192.168.1.1

删除默认网关:

ip route del default

5️⃣ 查看 MAC 地址

ifconfig

ifconfig | grep ether

ip

ip link show

6️⃣ ARP 表

ifconfig/arp

arp -n

ip

ip neigh

三、临时 vs 永久配置(重要)

⚠️ 注意:

  • ip 命令修改的是 运行时配置
  • 重启后会丢失

永久配置(Debian)

传统方式(仍可用)

编辑:

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

新方式(推荐,Debian 12+)

使用 NetworkManagersystemd-networkd

nmcli device status
nmcli con show

四、如果你真的还想用 ifconfig

安装旧工具:

sudo apt update
sudo apt install net-tools

⚠️ 不推荐长期使用


五、一句话总结

Debian 中,用 ip 替代 ifconfig,用 nmcli/etc/network/interfaces 做永久配置。

如果你愿意,我可以:

  • 给你一份 完整 ip 命令速查表
  • 帮你 从 ifconfig 迁移到 systemd-networkd
  • 针对 服务器 / 桌面 / 云主机 给你最佳方案

0