在 Debian(以及大多数 Linux 发行版)中,ifconfig 是一个传统的网络配置命令,用于查看和配置网络接口。不过需要注意:
Debian 新版本(如 Debian 10/11/12)默认可能没有
ifconfig,因为它属于net-tools包,而系统推荐使用ip命令。
sudo apt update
sudo apt install net-tools
安装后就可以使用 ifconfig 了。
ifconfig
或:
ifconfig -a
(-a 会显示未激活的接口)
示例输出:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
ether 08:00:27:xx:xx:xx txqueuelen 1000
ifconfig eth0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
⚠️ 重启后失效(仅当前会话有效)
sudo route add default gw 192.168.1.1
或用 ip:
sudo ip route add default via 192.168.1.1
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up
sudo ifconfig eth0 promisc
sudo ifconfig eth0 -promisc
ip addr
ip link
sudo ip link set eth0 up
sudo ip link set eth0 down
编辑:
/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
或重启网络:
sudo systemctl restart networking
| 功能 | 命令 |
|---|---|
| 查看网卡 | ifconfig |
| 配置 IP | ifconfig eth0 ip |
| 启停网卡 | ifconfig eth0 up/down |
| 新系统推荐 | ip 命令 |
如果你愿意,可以告诉我:
我可以给你更精确的命令。