ifconfig 和 ip 命令在 Linux 系统中都用于配置和显示网络接口信息,但它们之间存在一些关键区别:
ifconfig:
ip:
iproute2 包的一部分。ifconfig 的替代品,并且在大多数现代 Linux 发行版中默认安装。ifconfig:
ip:
ifconfig:
ifconfig eth0 up 或 ifconfig eth0 192.168.1.100 netmask 255.255.255.0ip:
ip addr add 192.168.1.100/24 dev eth0 或 ip link set eth0 upifconfig:
ip:
ip 命令。设置 IP 地址:
ifconfig eth0 192.168.1.100ip addr add 192.168.1.100/24 dev eth0启用接口:
ifconfig eth0 upip link set eth0 up查看路由表:
route -n(旧方法)ip route show虽然 ifconfig 在某些情况下仍然有用,但鉴于其过时的状态和 ip 命令的强大功能,建议优先使用 ip 命令来进行网络配置和管理。这不仅有助于保持系统的现代化,还能提供更好的性能和灵活性。