温馨提示×

debian ifconfig怎么使用

小樊
36
2026-10-09 11:36:19
栏目: 智能运维

在 Debian(以及大多数 Linux 发行版)中,ifconfig 是一个传统的网络配置命令,用于查看和配置网络接口。不过需要注意:

Debian 新版本(如 Debian 10/11/12)默认可能没有 ifconfig,因为它属于 net-tools 包,而系统推荐使用 ip 命令。


一、如果 ifconfig 不存在,先安装

sudo apt update
sudo apt install net-tools

安装后就可以使用 ifconfig 了。


二、ifconfig 常用用法

1️⃣ 查看所有网络接口

ifconfig

或:

ifconfig -a

(-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
      ether 08:00:27: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 netmask 255.255.255.0

⚠️ 重启后失效(仅当前会话有效)


5️⃣ 配置网关

sudo route add default gw 192.168.1.1

或用 ip:

sudo ip route add default via 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 官方推荐)

查看 IP

ip addr

查看接口状态

ip link

启停网卡

sudo ip link set eth0 up
sudo ip link set eth0 down

四、永久配置网络(Debian)

编辑:

/etc/network/interfaces

示例(静态 IP):

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 eth0 ip
启停网卡 ifconfig eth0 up/down
新系统推荐 ip 命令

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

  • Debian 版本
  • 你是服务器还是桌面
  • 想做什么(连网 / 固定 IP / 桥接 / 虚拟机)

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

0 踩