很多运维遇到过这个情景,想看服务器的ip地址时,按照教程的方法输入ifconfig,结果提示:-bash: ifconfig: 未找到命令。
在 Ubuntu 18.04+、CentOS 7+、Fedora 22+ 等较新的 Linux 发行版中,ifconfig 命令已被 ip 命令替代,其中一个原因是ifconfig 仅支持 IPv4/IPv6 基础配置,无法适配桥接、隧道等复杂网络场景,同时ifconfig 所属的 net-tools 工具包已多年未更新,而 iproute2(含 ip 命令)是 Linux 内核官方推荐的现代网络工具集。
如果想用回习惯已久的 ifconfig,可以这样安装:
# 基于 Debian/Ubuntu 系统# 更新软件包列表(确保获取最新版本)
apt update -y
# 安装net-tools(含ifconfig、route等旧命令)
apt install net-tools -y
# 基于 RedHat/CentOS 系统(如 CentOS 7、RHEL 8)
yum install net-tools -y
功能需求 | ifconfig | ip |
|---|
查看所有网卡信息 | ifconfig -a | ip addr show (简写 ip a) |
启用 / 禁用网卡 | ifconfig eth0 up/down | ip link set eth0 up/down |
配置临时 IP 地址 | ifconfig eth0 192.168.1.100 netmask 255.255.255.0 | ip addr add 192.168.1.100/24 dev eth0 |
删除ip | ifconfig eth0 0.0.0.0 | ip addr del 192.168.1.100/24 dev eth0 |
查看路由表 | route -n | ip route show (简写 ip r) |
添加默认网关 | route add default gw 192.168.1.1 | ip route add default via 192.168.1.1 |
删除路由 | route del default | ip route del default |
查看网络流量 | ifconfig eth0 | ip -s link show eth0 |
查看arp表 | arp -a | ip neigh show(简写ip n) |
添加静态 ARP 条目 | arp -s 192.168.1.100 00:11:22:33:44:55 | ip neigh add 192.168.1.00 lladdr 00:11:22:33:44:55 dev eth0 nud permanent |
参考链接:
https://mp.weixin.qq.com/s/_NI-_g2Ed2CUpctR8-akfQ