温馨提示×

Debian ifconfig如何启动网卡

小樊
53
2026-08-20 14:34:31
栏目: 智能运维

在 Debian 系统中,ifconfig 来自 net-tools 包,已经比较老旧,现代 Debian 更推荐使用 ip 命令。下面分别说明几种常见方式。


一、使用 ifconfig 启动网卡(不推荐但可用)

1. 查看网卡名称

ifconfig -a

ip addr

假设网卡名为 eth0(也可能是 ens33enp0s3 等)。

2. 启用网卡

sudo ifconfig eth0 up

3. 配置 IP(示例)

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

4. 添加默认网关

sudo route add default gw 192.168.1.1

5. 配置 DNS

编辑:

sudo nano /etc/resolv.conf

添加:

nameserver 8.8.8.8

⚠️ 注意
ifconfig 配置是临时的,重启后失效


二、使用 ip 命令(推荐)

启用网卡

sudo ip link set eth0 up

配置 IP

sudo ip addr add 192.168.1.100/24 dev eth0

添加网关

sudo ip route add default via 192.168.1.1

三、Debian 永久配置网卡(重启生效)

Debian 11 / 12(使用 /etc/network/interfaces

编辑:

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
    dns-nameservers 8.8.8.8

重启网络:

sudo systemctl restart networking

四、使用 NetworkManager(桌面或服务器可选)

nmcli device status
nmcli device connect eth0

五、常见问题

1. 没有 ifconfig?

安装:

sudo apt update
sudo apt install net-tools

2. 网卡 still down?

检查是否被 NetworkManager 管理,或查看:

ip link show eth0

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

  • Debian 版本(cat /etc/debian_version
  • 网卡名称
  • 是否服务器 / 桌面 / 虚拟机

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

0