温馨提示×

Debian怎么配置ifconfig

小樊
40
2026-08-20 13:58:33
栏目: 智能运维

Debian 里,ifconfig 命令来自 net-tools 包,但 Debian 默认已经不再推荐使用它,而是使用 ip 命令。下面分情况说明。


一、安装 ifconfig(如果命令不存在)

sudo apt update
sudo apt install net-tools

安装完成后即可使用:

ifconfig

二、临时配置网络(重启失效)

1️⃣ 查看网卡

ifconfig -a

ip addr

假设网卡名为 eth0


2️⃣ 配置 IP 地址

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

3️⃣ 启动 / 关闭网卡

sudo ifconfig eth0 up
sudo ifconfig eth0 down

4️⃣ 配置网关

sudo route add default gw 192.168.1.1

查看路由:

route -n

三、永久配置(推荐方式)

✅ Debian 10/11/12 推荐使用 /etc/network/interfaces

编辑配置文件:

sudo 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 114.114.114.114

DHCP 示例

auto eth0
iface eth0 inet dhcp

重启网络:

sudo systemctl restart networking

四、使用 NetworkManager(桌面环境常见)

查看设备:

nmcli device status

配置静态 IP:

nmcli con modify eth0 ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8"
nmcli con up eth0

五、ifconfig vs ip(建议)

功能 ifconfig ip 命令
查看 IP ifconfig ip addr
启动网卡 ifconfig up ip link set eth0 up
添加 IP ifconfig ip addr add

官方推荐:

ip addr
ip link
ip route

六、常见问题

❓ ifconfig 无输出

ifconfig -a

网卡可能未启动。

❓ 配置后无法上网

  • 检查网关
  • 检查 DNS
  • 检查路由:ip route

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

  • Debian 版本(如 11 / 12)
  • 服务器还是桌面
  • 网卡名称(ip addr 输出)

我可以帮你写一份 完全可用的配置方案

0