Is it possible to get network interface index not via /sys?

Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
So what I'm looking for is an interface index (or name) but the real one.if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:
# cat /sys/class/net/bond0.1007/ifindex
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23
Is there a way to do it with a function call or the only way is sysfs?
Thanks
sysfs network-interface ioctl
add a comment |Â
up vote
7
down vote
favorite
So what I'm looking for is an interface index (or name) but the real one.if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:
# cat /sys/class/net/bond0.1007/ifindex
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23
Is there a way to do it with a function call or the only way is sysfs?
Thanks
sysfs network-interface ioctl
Look at whatip link showdoes (probably using the netlink api)
â Stéphane Chazelas
Aug 14 '14 at 14:01
See also/proc/net/vlan/configor/proc/net/vlan/bond0.1007if it's a vlan interface.
â Stéphane Chazelas
Aug 14 '14 at 14:02
@StéphaneChazelas Thanks. I decided to keep using/sys./procor/sysare more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
â UVV
Aug 15 '14 at 10:39
1
the syscalls would be the sendmsg/recvmsg using the netlink socket API.
â Stéphane Chazelas
Aug 15 '14 at 10:52
1
rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issueRTM_GETLINKmessage and look forIFLA_LINKattribute in reply.
â ecatmur
Mar 23 '15 at 19:50
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
So what I'm looking for is an interface index (or name) but the real one.if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:
# cat /sys/class/net/bond0.1007/ifindex
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23
Is there a way to do it with a function call or the only way is sysfs?
Thanks
sysfs network-interface ioctl
So what I'm looking for is an interface index (or name) but the real one.if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:
# cat /sys/class/net/bond0.1007/ifindex
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23
Is there a way to do it with a function call or the only way is sysfs?
Thanks
sysfs network-interface ioctl
sysfs network-interface ioctl
asked Aug 14 '14 at 10:35
UVV
2,0651325
2,0651325
Look at whatip link showdoes (probably using the netlink api)
â Stéphane Chazelas
Aug 14 '14 at 14:01
See also/proc/net/vlan/configor/proc/net/vlan/bond0.1007if it's a vlan interface.
â Stéphane Chazelas
Aug 14 '14 at 14:02
@StéphaneChazelas Thanks. I decided to keep using/sys./procor/sysare more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
â UVV
Aug 15 '14 at 10:39
1
the syscalls would be the sendmsg/recvmsg using the netlink socket API.
â Stéphane Chazelas
Aug 15 '14 at 10:52
1
rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issueRTM_GETLINKmessage and look forIFLA_LINKattribute in reply.
â ecatmur
Mar 23 '15 at 19:50
add a comment |Â
Look at whatip link showdoes (probably using the netlink api)
â Stéphane Chazelas
Aug 14 '14 at 14:01
See also/proc/net/vlan/configor/proc/net/vlan/bond0.1007if it's a vlan interface.
â Stéphane Chazelas
Aug 14 '14 at 14:02
@StéphaneChazelas Thanks. I decided to keep using/sys./procor/sysare more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
â UVV
Aug 15 '14 at 10:39
1
the syscalls would be the sendmsg/recvmsg using the netlink socket API.
â Stéphane Chazelas
Aug 15 '14 at 10:52
1
rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issueRTM_GETLINKmessage and look forIFLA_LINKattribute in reply.
â ecatmur
Mar 23 '15 at 19:50
Look at what
ip link show does (probably using the netlink api)â Stéphane Chazelas
Aug 14 '14 at 14:01
Look at what
ip link show does (probably using the netlink api)â Stéphane Chazelas
Aug 14 '14 at 14:01
See also
/proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.â Stéphane Chazelas
Aug 14 '14 at 14:02
See also
/proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.â Stéphane Chazelas
Aug 14 '14 at 14:02
@StéphaneChazelas Thanks. I decided to keep using
/sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.â UVV
Aug 15 '14 at 10:39
@StéphaneChazelas Thanks. I decided to keep using
/sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.â UVV
Aug 15 '14 at 10:39
1
1
the syscalls would be the sendmsg/recvmsg using the netlink socket API.
â Stéphane Chazelas
Aug 15 '14 at 10:52
the syscalls would be the sendmsg/recvmsg using the netlink socket API.
â Stéphane Chazelas
Aug 15 '14 at 10:52
1
1
rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue
RTM_GETLINK message and look for IFLA_LINK attribute in reply.â ecatmur
Mar 23 '15 at 19:50
rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue
RTM_GETLINK message and look for IFLA_LINK attribute in reply.â ecatmur
Mar 23 '15 at 19:50
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
add a comment |Â
up vote
0
down vote
The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
answered Sep 7 at 19:53
Boscoe
1364
1364
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f150216%2fis-it-possible-to-get-network-interface-index-not-via-sys%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Look at what
ip link showdoes (probably using the netlink api)â Stéphane Chazelas
Aug 14 '14 at 14:01
See also
/proc/net/vlan/configor/proc/net/vlan/bond0.1007if it's a vlan interface.â Stéphane Chazelas
Aug 14 '14 at 14:02
@StéphaneChazelas Thanks. I decided to keep using
/sys./procor/sysare more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.â UVV
Aug 15 '14 at 10:39
1
the syscalls would be the sendmsg/recvmsg using the netlink socket API.
â Stéphane Chazelas
Aug 15 '14 at 10:52
1
rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue
RTM_GETLINKmessage and look forIFLA_LINKattribute in reply.â ecatmur
Mar 23 '15 at 19:50