linux临时配置mac地址,Linux获取网卡型号、mac地址、修改IP地址的几种方法

1569726912754.html

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值