eth0:获取接口信息时出错:找不到设备

时间:2016-07-23 08:52:41

标签: ubuntu ethernet ifconfig

当我在Ubuntu 16.4 shell中输入此代码时:

INTERFACE=eth0
IP=$(ifconfig $INTERFACE | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')

...我收到以下错误消息:

  

eth0:获取接口信息时出错:找不到设备

我无法弄清楚如何解决这个问题。 命令“fconfig -a”给出以下输出:

docker0   Link encap:Ethernet  HWaddr 02:42:59:cd:db:0a  
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:59ff:fecd:db0a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:38 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2588 (2.5 KB)  TX bytes:7870 (7.8 KB)

enp0s31f6 Link encap:Ethernet  HWaddr 84:7b:eb:33:e9:a0  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:65967 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19250 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:32913423 (32.9 MB)  TX bytes:4796536 (4.7 MB)
          Interrupt:16 Memory:e1200000-e1220000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:40501 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40501 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:5857145 (5.8 MB)  TX bytes:5857145 (5.8 MB)

veth09540a8 Link encap:Ethernet  HWaddr 0e:b6:ea:a4:94:46  
          inet6 addr: fe80::cb6:eaff:fea4:9446/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:648 (648.0 B)  TX bytes:8626 (8.6 KB)

vetha2b6c34 Link encap:Ethernet  HWaddr 5a:d6:8a:38:35:ab  
          inet6 addr: fe80::58d6:8aff:fe38:35ab/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:117 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:648 (648.0 B)  TX bytes:15820 (15.8 KB)

wlp1s0    Link encap:Ethernet  HWaddr e4:b3:18:12:2c:21  
          inet addr:192.168.0.197  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::1ff6:1288:2616:7cff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:715706 errors:0 dropped:0 overruns:0 frame:0
          TX packets:366309 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:800058455 (800.0 MB)  TX bytes:110982989 (110.9 MB)

1 个答案:

答案 0 :(得分:-1)

我不知道你有什么样的系统,但没有eth0存在。 使用

INTERFACE=wlp1s0
相反,您将获得您可能想知道的IP(但请注意,这是无线网卡的IP)。