在 Debian(以及大多数 Linux 发行版)里,ifconfig 是用来查看和配置网络接口的命令。不过要注意:新版本 Debian 默认可能没有安装 ifconfig,而是推荐使用 ip 命令。
下面分几部分说明。
在终端执行:
ifconfig
如果提示:
command not found
说明没安装,可以安装:
sudo apt update
sudo apt install net-tools
然后再用 ifconfig。
ifconfig
或只看启用的接口:
ifconfig -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
inet6 fe80::20c:29ff:fe... prefixlen 64
ether 00:0c:29:xx:xx:xx txqueuelen 1000
ifconfig eth0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 192.168.1.100
设置 IP 和子网掩码:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo ifconfig eth0 broadcast 192.168.1.255
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
⚠️ ifconfig 已逐渐被淘汰
ip 命令ifconfig 修改是临时生效,重启后失效ip addr
ip link set eth0 up
ip link set eth0 down
sudo ip addr add 192.168.1.100/24 dev eth0
编辑:
sudo nano /etc/network/interfaces
示例:
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
如果你愿意,可以告诉我:
我可以给你更精确的命令。