在 Linux 中,ifconfig 是一个传统的网络配置命令(来自 net-tools 包),用于查看和临时配置网卡。需要注意的是:
ifconfig 配置是临时生效的,重启网络或系统后会失效ip 命令或 nmcli / 网络配置文件下面按常见场景说明如何用 ifconfig 配置网卡。
ifconfig
或查看指定网卡:
ifconfig eth0
启用网卡
ifconfig eth0 up
禁用网卡
ifconfig eth0 down
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
ifconfig eth0 netmask 255.255.255.0
ifconfig 不能设置默认网关,需要用 route 或 ip:
route add default gw 192.168.1.1
或使用 ip 命令(推荐):
ip route add default via 192.168.1.1
ifconfig eth0 down
ifconfig eth0 hw ether 00:11:22:33:44:55
ifconfig eth0 up
ifconfig eth0 promisc # 开启
ifconfig eth0 -promisc # 关闭
ifconfig eth0 mtu 1500
ifconfig 无法实现永久配置,常见方式:
编辑:
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/network/interfaces
使用 netplan:
/etc/netplan/*.yaml
ip addr show
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0
ip route add default via 192.168.1.1
如果你愿意,可以告诉我:
eth0、ens33)我可以给你更精确的配置示例。