1.获取所有有(无)网卡型号
方法一、ifconfig
用法:ifconfig | grep | cut -d ':' -f 1
ubuntu
root@ubuntu:~# ifconfig | grep enp| cut -d ':' -f 1
enp2s0
enp3s0
centos
[root@centos ~]# ifconfig | grep ens| cut -d ':' -f 1
ens192
注意:ubuntu下有线网卡基本以enp开头,centos以ens开头,无线网卡下ubuntu以wlp开头
方法二、ip a
用法:ip a | grep | cut -d ':' -f 2 | awk '{print $1}' | grep
ubuntu
root@ubuntu:~# ip a | grep enp | cut -d ':' -f 2 | awk '{print $1}' | grep enp
enp2s0
enp3s0
centos
[root@centos ~]# ip a | grep ens | cut -d ':' -f 2 | awk '{print $1}' | grep ens
ens192
方法三、ls /sys/class/net (推荐)
用法:ls /sys/class/net | grep
root@ubuntu:~# ls /sys/class/net | grep enp
enp2s0
enp3s0
2.获取有(无)线网卡对应mac地址
用法:cat /sys/class/net//address
root@ubuntu:~# cat /sys/class/net/enp2s0/address
f4:8e:38:ad:34:6d
3.获取有(无)线网卡对应的IP地址
用法:ifconfig | grep inet | grep -v inet6 | sed 's/^[ \t]*//g' | cut -d ' ' -f 2| awk '{print $1}'
root@ubuntu:~# ifconfig enp2s0 | grep inet | grep -v inet6 | sed 's/^[ \t]*//g' | cut -d ' ' -f 2| awk '{print $1}'
192.168.81.208
4.补充:查看某个网卡信息
root@ubutun:~# ifconfig enp2s0
enp2s0: flags=4163 mtu 1500
inet 192.168.81.208 netmask 255.255.254.0 broadcast 192.168.81.255
inet6 fe80::c0b1:bc04:43a5:9eab prefixlen 64 scopeid 0x20
ether f4:8e:38:ad:34:6d txqueuelen 1000 (以太网)
RX packets 39571544 bytes 5640943675 (5.6 GB)
RX errors 0 dropped 1989163 overruns 0 frame 0
TX packets 45318631 bytes 36700361403 (36.7 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu:~# ip a s enp2s0
2: enp2s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether