Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a question related to the veth pair that is used in Linux system. I want to know which veth pairs are running in the current host, which I mean querying the pairs by using one Linux command or finding the related configuration in some files.

I know that to construct veth pair, you can simply by using

ip link add name1 type veth name2

But I haven't found an command or file that could be used to query the current running veth pairs.

If you know a way that could find the current running veth pairs, could you please tell me? This would help me a lot.

share|improve this question

You can get peer ifindex with the following ethtool command.

# ethtool -S veth1
NIC statistics:
     peer_ifindex: 7

ifindex is shown with:

# ip link

Ref: http://www.spinics.net/lists/netdev/msg102062.html

share|improve this answer
    
very nice, thanks – Neil McGill Nov 21 '14 at 16:58

I have an older linux kernel without ip netns so I cobbled this together to get the needed info. Assuming you can ssh into your LXC containers, this might be of use to you. It's a quick hack 8)

MY_VMS="10.0.1.1" # etc... change as needed
for A_VM in $MY_VMS
do
  if [ ! -f $A_VM.list ]
  then
    ssh $A_VM ip link list > $A_VM.list
  fi

  for i in `ifconfig -a | grep "Link encap" | sed 's/ .*//g'`
  do
    PEER_IFINDEX=`ethtool -S $i 2>/dev/null | grep peer_ifindex | sed 's/ *peer_ifindex: *//g' `
    if [ "$PEER_IFINDEX" = "" ]
    then
      continue
    fi

    PEER_IF=`grep "^$PEER_IFINDEX:" $A_VM.list  | awk '{print $2}' | sed 's/:.*//g'`
    if [ "$PEER_IF" = "" ]
    then
      continue
    fi
    printf "%-10s is paired with %-10s on %-20s\n" $i $PEER_IF $A_VM
  done
done
share|improve this answer

With this simple script you can find the pairs (for OpenStack):

#!/bin/bash
for i in `ifconfig -a |grep qv |awk -F: '{print $1}'` ;
   do
      echo "---------------"
      echo $i
      echo "Our ID: " `ip link show dev $i | grep $i | awk -F: '{print $1}'`
      echo "Peer ID: " `ethtool -S $i |  grep -i peer_ifindex | awk -F: '{print $2}'`
      echo "---------------"
done

In OpenStack veth pairs - veth interface names starts with qv*.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .