Gentoo Archives: gentoo-user

From: David Haller <gentoo@×××××××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] How can I check for haveing an ethernet "device"
Date: Tue, 21 Jul 2015 07:15:44
Message-Id: 20150721003348.GA6671@grusum.endjinn.de
In Reply to: [gentoo-user] How can I check for haveing an ethernet "device" by Meino.Cramer@gmx.de
1 Hello,
2
3 On Mon, 20 Jul 2015, Meino.Cramer@×××.de wrote:
4 >on an embedded system I want to check, whether I have an eth0 "device"
5 >(ok, I know, it is not an device in the usual way...), when I attach
6 >an USB2Ethernet gadget via OTG-cable to it and whether all needed
7 >drivers are already there...
8 >
9 >How can I do that with at least impact at possible ?
10
11 LC_ALL=C ip link show eth0 | grep -q 'state UP'
12
13 if it's there, but no link, it's 'state DOWN' in the output.
14
15 Example output:
16
17 # ip link show eth0
18 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1492 qdisc pfifo_fast state UP qlen 1000
19 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
20 # ip link show eth1
21 3: eth1: <BROADCAST> mtu 1492 qdisc pfifo_fast state DOWN qlen 1000
22 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
23
24 and with the module for eth1 unloaded:
25
26 # ip link show eth1
27 # [nothing]
28
29 There's also other 'show' subcommands, most notably 'ip addr show',
30 with which you could check if you got an ip assigned.
31
32 Both commands show all devices if you omit the device argument (eth*
33 above).
34
35 'ip' belongs to sys-apps/iproute2 and is the standard tool to set up
36 networking stuff (besides wifi) and thus already installed.
37
38 HTH,
39 -dnh
40
41 --
42 "There is hopeful symbolism in the fact that flags do not wave in a
43 vacuum."
44 -- Arthur C. Clarke