设备管理

网卡

罗列

终端运行 ip link 命令,即可看到系统所有网卡的详细信息:

  1. $ ip link
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
  3. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
  5. link/ether 08:00:27:31:1f:2a brd ff:ff:ff:ff:ff:ff
  6. 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
  7. link/ether 08:00:27:f4:74:b8 brd ff:ff:ff:ff:ff:ff

启停

启用网卡,请运行以下命名:

  1. $ ip link set eth1 up

命令成功执行后,网卡即处于活跃(工作)状态。

相应地,停用网卡则是:

  1. $ ip link set eth1 down

地址设置

运行 ip addr 可以查看所有网卡设置的地址:

  1. $ ip addr
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
  3. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4. inet 127.0.0.1/8 scope host lo
  5. valid_lft forever preferred_lft forever
  6. inet6 ::1/128 scope host
  7. valid_lft forever preferred_lft forever
  8. 2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
  9. link/ether 08:00:27:31:1f:2a brd ff:ff:ff:ff:ff:ff
  10. inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
  11. valid_lft forever preferred_lft forever
  12. 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
  13. link/ether 08:00:27:f4:74:b8 brd ff:ff:ff:ff:ff:ff
  14. inet 192.168.56.3/24 brd 192.168.56.255 scope global eth1
  15. valid_lft forever preferred_lft forever
  16. inet6 fe80::a00:27ff:fef4:74b8/64 scope link
  17. valid_lft forever preferred_lft forever

其中, link 一行是数据链路层地址,也就是 MAC 地址(或者称为物理地址);inet 一行是网络层地址( IPv4 ),也就是我们所熟知的 IP 地址;inet6 一行也是网络层地址( IPv6 ),目前应用还不广。

如果只想显示某个网卡,可以在命令后面指定:

  1. $ ip addr show dev eth0
  2. 2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
  3. link/ether 08:00:27:31:1f:2a brd ff:ff:ff:ff:ff:ff
  4. inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
  5. valid_lft forever preferred_lft forever

下一步

订阅更新,获取更多学习资料,请关注我们的 微信公众号

../../_images/wechat-mp-qrcode.png小菜学编程

微信打赏