温馨提示×

debian ifconfig怎么用

小樊
41
2026-09-09 13:44:54
栏目: 智能运维

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

下面分几部分说明。


一、先确认 ifconfig 是否可用

在终端执行:

ifconfig

如果提示:

command not found

说明没安装,可以安装:

sudo apt update
sudo apt install net-tools

然后再用 ifconfig


二、常用 ifconfig 用法

1️⃣ 查看所有网络接口

ifconfig

或只看启用的接口:

ifconfig -a

输出示例:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
      inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
      inet6 fe80::20c:29ff:fe...  prefixlen 64
      ether 00:0c:29:xx:xx:xx  txqueuelen 1000

2️⃣ 查看指定网卡

ifconfig eth0

3️⃣ 启用 / 禁用网卡

sudo ifconfig eth0 up
sudo ifconfig eth0 down

4️⃣ 设置 IP 地址

sudo ifconfig eth0 192.168.1.100

设置 IP 和子网掩码:

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

5️⃣ 设置广播地址

sudo ifconfig eth0 broadcast 192.168.1.255

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

三、ifconfig 的局限(重要)

⚠️ ifconfig 已逐渐被淘汰

  • Debian 官方推荐:ip 命令
  • ifconfig 修改是临时生效,重启后失效

四、现代替代方案(推荐)

查看 IP

ip addr

启用 / 禁用网卡

ip link set eth0 up
ip link set eth0 down

设置 IP

sudo ip addr add 192.168.1.100/24 dev eth0

五、永久配置 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 版本(如 11 / 12)
  • 是想 看 IP改 IP 还是 排错

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

0