简介
ifconfig, 全称是network interfaces configuring。是linux中用于显示或配置网络设备(网络接口卡)的命令
安装
有些最小化安装CentOS等Linux发行版的时候会默认不安装ifconfig等命令。此时终端运行ifconfig命令就会出错,ifconfig这个命令来源于net-tools,则安装即可:
yum install net-tools
查看当前网络接口的情况
[root@localhost ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.46 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe7a:9880 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:7a:98:80 txqueuelen 1000 (Ethernet)
RX packets 2792 bytes 437764 (427.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 711 bytes 161168 (157.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 12 bytes 1020 (1020.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 1020 (1020.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
执行ifconfig无输出
检查 /sbin/ifconfig
通常情况下,ifconfig如果有显示,但没有某一项的信息(比如识别不到网卡)时,可以先检查/etc/sysconfig/network-scripts/下的配置文件是否正确
ifconfig及/sbin/ifconfig没有任何的输出,因此先检查了下/sbin/ifconfig文件。发现有以下错误:
[root@localhost ~]# ls -al /sbin/ifconfig
-rwxr-xr-x. 1 root root 0 May 11 15:53 /sbin/ifconfig
[root@localhost ~]# file /sbin/ifconfig
/sbin/ifconfig: empty
简单的解决方案就是从其它服务器内复制一份到当前服务器,再次执行即可
在CentOS最小化服务器版本中如何查找网卡IP和其它详细信息
CentOS7最小化系统中,由于没有ifconfig,可以使用”ip addr”和”ip link”命令来查找网卡详情,统计数据可以使用”ip -s link”
例如要查看网卡信息:
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:7a:98:80 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.46/24 brd 192.168.1.255 scope global dynamic enp0s3
valid_lft 84522sec preferred_lft 84522sec
inet6 fe80::a00:27ff:fe7a:9880/64 scope link
valid_lft forever preferred_lft forever