温馨提示×

debian ifconfig怎样使用

小樊
52
2026-09-06 16:07:57
栏目: 智能运维

在 Debian(以及大多数 Linux 发行版)中,ifconfig 是用于查看和配置网络接口的传统命令。不过需要注意:新版本 Debian 默认可能未安装 ifconfig,更推荐使用 ip 命令。

下面分几个部分说明。


一、检查是否可用

ifconfig

如果提示:

command not found

说明没有安装,可用以下命令安装:

sudo apt update
sudo apt install net-tools

二、常用 ifconfig 用法

1️⃣ 查看所有网络接口

ifconfig

或只看启用的接口:

ifconfig -a

输出示例:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>
      inet 192.168.1.10  netmask 255.255.255.0
      inet6 fe80::20c:29ff:fe...

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️⃣ 配置网关

sudo route add default gw 192.168.1.1

6️⃣ 修改 MAC 地址

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

7️⃣ 开启 / 关闭混杂模式

sudo ifconfig eth0 promisc
sudo ifconfig eth0 -promisc

三、推荐替代命令(Debian 官方倾向)

Debian 官方更推荐 ip 命令:

ip addr show
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0

四、永久配置 IP(Debian)

ifconfig 只能临时配置,永久配置用:

Debian 11 及以下

编辑:

/etc/network/interfaces

Debian 12+(常用 systemd-networkd 或 NetworkManager)


如果你愿意,可以告诉我:

  • Debian 版本(cat /etc/debian_version
  • 你是服务器还是桌面
  • 想实现什么(改 IP / 看流量 / 排查网络)

我可以给你更精确的命令。

0