温馨提示×

debian ifconfig怎么配置

小樊
72
2026-09-24 20:49:31
栏目: 智能运维

在 Debian 里,ifconfig 本身只能查看和临时配置网络,不能“永久保存”配置。永久配置要靠 /etc/network/interfaces(传统方式)或 netplan / NetworkManager(新版本)。

下面按常见用法说明。


一、先说明:ifconfig 是临时配置

ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up

✅ 立即生效
❌ 重启后失效


二、临时配置(ifconfig 用法)

1️⃣ 查看网卡

ifconfig

或

ip addr

2️⃣ 配置 IP

ifconfig eth0 192.168.1.100 netmask 255.255.255.0

3️⃣ 启用 / 禁用网卡

ifconfig eth0 up
ifconfig eth0 down

4️⃣ 配置网关(ifconfig 不带网关)

route add default gw 192.168.1.1

三、永久配置(推荐)

✅ 方法一:/etc/network/interfaces(Debian 经典方式)

编辑:

nano /etc/network/interfaces

静态 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 8.8.4.4

DHCP 示例

auto eth0
iface eth0 inet dhcp

应用:

systemctl restart networking

或

ifdown eth0 && ifup eth0

✅ 方法二:NetworkManager(桌面版常见)

nmtui

图形化配置,最简单。


✅ 方法三:netplan(Debian 12+ 有时用)

nano /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    eth0:
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8]
netplan apply

四、建议

  • 服务器:用 /etc/network/interfaces
  • 桌面:用 NetworkManager
  • 临时调试:才用 ifconfig

如果你告诉我:

  • Debian 版本(11 / 12)
  • 网卡名(eth0 / ens33)
  • 静态还是 DHCP

我可以直接给你一份可直接复制用的配置。

0 踩