温馨提示×

debian如何用ifconfig

小樊
46
2026-09-30 16:35:40
栏目: 智能运维

在 Debian 中,ifconfig 属于 net-tools 工具包,而较新版本的 Debian 默认只装了 ip 命令(来自 iproute2)。下面分情况说明怎么用。


一、Debian 没有 ifconfig 怎么办

1. 安装 net-tools

sudo apt update
sudo apt install net-tools

安装完成后即可使用:

ifconfig

二、常用 ifconfig 用法

1. 查看所有网络接口

ifconfig

或(不省略未启用的接口):

ifconfig -a

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:0 192.168.1.101 netmask 255.255.255.0

6. 修改 MAC 地址

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

三、Debian 推荐方式(替代 ifconfig)

Debian 官方更推荐使用 ip 命令:

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

四、说明

  • ifconfig 临时生效,重启后失效
  • 永久配置应修改:
    • Debian 11 及以下:/etc/network/interfaces
    • Debian 12+(用 NetworkManager):nmcli 或 GUI

如果你愿意,可以告诉我你的 Debian 版本 和 使用场景(服务器 / 桌面 / 容器),我可以给你更合适的配置方式。

0 踩