在 Jessie 和 Stretch 上解析 eth0 IP 的稳定命令

在 Jessie 和 Stretch 上解析 eth0 IP 的稳定命令

所以一些天才改变了它的打印方式。在带有 Raspbian (Debian Jessie) 的 Raspberry 上:

$ /sbin/ifconfig eth0
eth0      Link encap:Ethernet  HWaddr b8:27:eb:71:d5:56  
      inet addr:192.168.0.11  Bcast:192.168.0.255  Mask:255.255.255.0
      inet6 addr: fe80::1e43:2c74:e7d6:6419/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:165 errors:0 dropped:0 overruns:0 frame:0
      TX packets:135 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:17459 (17.0 KiB)  TX bytes:18391 (17.9 KiB)

在我的笔记本电脑上(Debian Stretch):

$ /sbin/ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.0.77  netmask 255.255.255.0  broadcast 192.168.0.255
    inet6 fe80::39db:8c13:722f:b088  prefixlen 64  scopeid 0x20<link>
    ether 40:b0:34:96:d9:02  txqueuelen 1000  (Ethernet)
    RX packets 118126  bytes 23261567 (22.1 MiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 319445  bytes 452933203 (431.9 MiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device interrupt 16  memory 0xcc200000-cc220000  

我有解析 的代码"inet addr:",这显然在笔记本电脑上失败了。是否有一种独特的方法可以使用 shell 命令获取 Raspbian/Jessie 和 Stretch 上的 eth0 IP 地址?

答案1

这在两个系统上的格式相同:

$ ip a show eth0 # stretch
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 40:b0:34:96:d9:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.77/24 brd 192.168.0.255 scope global eth0
   valid_lft forever preferred_lft forever
inet6 fe80::39db:8c13:722f:b088/64 scope link tentative 
   valid_lft forever preferred_lft forever

$ ip a show eth0 # raspbian jessie
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:71:d5:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.11/24 brd 192.168.0.255 scope global eth0
   valid_lft forever preferred_lft forever
inet6 fe80::1e43:2c74:e7d6:6419/64 scope link 
   valid_lft forever preferred_lft forever

相关内容