温馨提示×

debian ifconfig怎样设置

小樊
38
2026-09-21 19:04:01
栏目: 智能运维

在 Debian 系统中,ifconfig 属于 net-tools 工具包,用来查看和临时配置网络接口。需要注意:

  • ifconfig 设置是临时的,重启后失效
  • Debian 较新版本推荐使用 ip 命令或改 /etc/network/interfaces

下面分情况说明。


一、安装 ifconfig(如没有)

sudo apt update
sudo apt install net-tools

二、查看网络接口

ifconfig

或指定接口:

ifconfig eth0

三、临时设置 IP 地址

1️⃣ 设置 IP 和子网掩码

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

2️⃣ 开启 / 关闭接口

sudo ifconfig eth0 up
sudo ifconfig eth0 down

3️⃣ 设置广播地址(可选)

sudo ifconfig eth0 broadcast 192.168.1.255

4️⃣ 设置 MTU(可选)

sudo ifconfig eth0 mtu 1400

四、设置网关(ifconfig 不能设网关)

ifconfig 不能设置默认网关,需用 route 或 ip:

sudo route add default gw 192.168.1.1

或用 ip 命令(推荐):

sudo ip route add default via 192.168.1.1

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

编辑:

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

重启网络:

sudo systemctl restart networking

六、Debian 新版本说明

Debian 10+ 更推荐:

ip addr show
ip addr add 192.168.1.100/24 dev eth0
ip link set eth0 up

如果你告诉我:

  • Debian 版本
  • 网络接口名(eth0 / ens33)
  • 静态还是 DHCP

我可以给你精确配置命令。

0 踩