温馨提示×

Debian如何调用ifconfig

小樊
39
2026-08-31 10:48:42
栏目: 智能运维

Debian 中调用 ifconfig,需要注意一个现实情况:ifconfig 已经被逐步淘汰,默认 很多 Debian 版本(尤其是最小化安装)不再自带

下面分情况说明如何调用和使用。


一、为什么 Debian 里可能没有 ifconfig?

ifconfig 属于 net-tools 工具包,Debian 默认倾向于使用 iproute2ip 命令)。

检查是否已安装:

which ifconfig

如果 没有输出,说明未安装。


二、安装 ifconfig(推荐方式)

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️⃣ 设置网关(不是 ifconfig 直接完成)

sudo route add default gw 192.168.1.1

四、Debian 推荐的新方式(强烈建议)

使用 ip 命令(替代 ifconfig)

功能 ifconfig ip 命令
查看网卡 ifconfig ip addr
启动网卡 ifconfig up ip link set eth0 up
设置 IP ifconfig ip addr add 192.168.1.100/24 dev eth0
查看路由 route ip route

示例:

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

五、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

六、总结建议

临时查看/调试 → 可以安装 net-toolsifconfig
长期维护 / 服务器 → 推荐使用 ip 命令
永久配置 → 修改 /etc/network/interfaces

如果你愿意,我可以:

  • 帮你 判断当前 Debian 版本
  • 迁移 ifconfig 用法到 ip 命令
  • 针对 无桌面 / 桌面版 Debian 给出具体配置示例

0