温馨提示×

如何在Debian使用ifconfig

小樊
33
2026-07-21 20:41:42
栏目: 智能运维

在 Debian 系统中,ifconfig 属于 net-tools 工具包,而现代 Debian 默认更倾向于使用 ip 命令(来自 iproute2)。下面分情况说明如何在 Debian 中使用 ifconfig


一、检查是否已安装 ifconfig

先确认 ifconfig 是否可用:

ifconfig

如果提示:

bash: ifconfig: command not found

说明 net-tools 未安装


二、安装 ifconfig(推荐方式)

1️⃣ 更新软件源

sudo apt update

2️⃣ 安装 net-tools

sudo apt install net-tools

安装完成后即可使用:

ifconfig

三、常用 ifconfig 用法示例

1️⃣ 查看所有网络接口

ifconfig -a

2️⃣ 查看指定网卡(如 eth0)

ifconfig eth0

3️⃣ 启用网卡

sudo ifconfig eth0 up

4️⃣ 禁用网卡

sudo ifconfig eth0 down

5️⃣ 配置 IP 地址

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

6️⃣ 添加网关(ifconfig 本身不能设置网关)

sudo route add default gw 192.168.1.1

四、Debian 更推荐的方式(ip 命令)

现代 Debian 建议使用 ip 命令替代 ifconfig

查看网卡

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)

ifconfigip 命令 重启后失效,永久配置请编辑:

sudo nano /etc/network/interfaces

示例(DHCP):

auto eth0
iface eth0 inet dhcp

示例(静态 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

六、总结建议

场景 建议
临时调试 ipifconfig
永久配置 /etc/network/interfaces
新系统 优先使用 ip 命令

如果你告诉我 Debian 版本(如 10 / 11 / 12)或 服务器/桌面环境,我可以给你更精确的配置方案。

0