温馨提示×

Debian怎么用ifconfig

小樊
49
2026-08-31 10:35:42
栏目: 智能运维

Debian 里,ifconfig 属于比较“老”的命令,现在默认 不一定自带。下面分情况说明怎么用。


一、先说明:ifconfig 是否还能用?

  • Debian 10 及以后:默认 没有安装 ifconfig
  • 仍然可以用,只是需要手动安装

二、安装 ifconfig

ifconfignet-tools 包里:

sudo apt update
sudo apt install net-tools

安装完成后就可以用了。


三、常用 ifconfig 用法

1️⃣ 查看网络接口

ifconfig

或只看某个网卡,例如 eth0:

ifconfig eth0

2️⃣ 启动 / 关闭网卡

sudo ifconfig eth0 up
sudo ifconfig eth0 down

3️⃣ 设置 IP 地址

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

4️⃣ 设置网关(ifconfig 做不到)

ifconfig 不能设置网关,需要配合 route

sudo route add default gw 192.168.1.1

5️⃣ 启用 / 禁用混杂模式(抓包常用)

sudo ifconfig eth0 promisc
sudo ifconfig eth0 -promisc

四、临时配置 vs 永久配置

⚠️ ifconfig 修改的都是临时的,重启失效

永久配置(推荐方式)

Debian 推荐用 ip / networkctl / /etc/network/interfaces

方法 1:/etc/network/interfaces(传统)

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 官方更推荐用 ip 命令:

ip addr          # 查看 IP
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0
ip route add default via 192.168.1.1

六、总结一句话

老系统 / 习惯用 ifconfig

sudo apt install net-tools
ifconfig

新系统 / 推荐做法

ip addr

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

  • Debian 版本(10 / 11 / 12)
  • 服务器还是桌面
  • 是否用 DHCP 或静态 IP

我可以给你一套最适合你环境的配置方案

0