温馨提示×

Debian怎么使用ifconfig

小樊
38
2026-08-20 13:53:31
栏目: 智能运维

Debian 里,ifconfig 属于比较老的网络工具,现在已经默认不再安装。下面分情况说明怎么用。


一、ifconfig 在哪?为什么用不了?

  • ifconfig 来自 net-tools 软件包
  • 现代 Debian 默认使用 iproute2ip 命令)
  • 所以直接执行会提示:
    bash: ifconfig: command not found
    

二、在 Debian 上安装 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

四、推荐:使用 ip 命令(现代方式)

Debian 官方更推荐 ip 命令:

查看网卡

ip addr

启用 / 禁用网卡

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

设置 IP

sudo ip addr add 192.168.1.100/24 dev eth0

设置网关

sudo ip route add default via 192.168.1.1

五、Debian 网络配置方式(补充)

  • 临时配置ifconfig / ip
  • 永久配置
    • /etc/network/interfaces
    • 或 NetworkManager(桌面环境)

例如 /etc/network/interfaces

auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1

六、总结

✅ 想用 ifconfig → 装 net-tools
✅ 新系统 → 推荐用 ip
✅ 临时配置 → ip / ifconfig
✅ 永久配置 → /etc/network/interfaces 或 NetworkManager

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

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

我可以给你更精确的配置示例。

0