Debian 使用 ifconfig 更新网络配置的实用步骤
一 识别接口与工具准备
- 查看接口名称与状态:执行命令查看所有接口(含未激活)如:ifconfig -a 或 ip addr。常见以太网接口名可能为 eth0、enp0s3 等。
- 安装 ifconfig:在新版本 Debian 中 ifconfig 已被标记为弃用,若系统未安装,可先安装 net-tools:sudo apt update && sudo apt install net-tools -y。
- 注意:ifconfig 仅用于查看与临时配置,重启后更改会丢失,需通过配置文件或工具实现持久化。
二 临时修改 IP 地址与路由(立即生效,重启后失效)
- 设置静态 IP 与子网掩码(示例接口 eth0):sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up。
- 设置默认网关:sudo route add default gw 192.168.1.1 eth0。
- 其他常用参数示例:
- 调整 MTU:sudo ifconfig eth0 mtu 1500
- 设置广播地址:sudo ifconfig eth0 broadcast 192.168.1.255
- 验证:ifconfig eth0 查看是否生效。
- 提示:部分参数更改前可先执行 sudo ifconfig eth0 down,改完再 sudo ifconfig eth0 up。
三 持久化配置静态 IP(推荐)
四 持久化配置动态 IP(DHCP)
五 DNS 设置与其他方式