I am working on vxlan tunneling between Linux - commercial routers. I need to debug some interface settings.

The command sudo ip -d link show DEV gives me a great output but the output format is like a long single line as below.

katabey@leaf-1:mgmt:~$ sudo ip -d link show vxlan_10
11: vxlan_10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9216 qdisc noqueue master bridge state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 52:6d:3d:aa:b5:bf brd ff:ff:ff:ff:ff:ff promiscuity 1 minmtu 68 maxmtu 65535 
    vxlan id 10010 local srcport 0 0 dstport 4789 nolearning ttl 64 ageing 300 udpcsum noudp6zerocsumtx noudp6zerocsumrx 
    bridge_slave state forwarding priority 8 cost 100 hairpin off guard off root_block off fastleave off learning off flood on port_id 0x8002 port_no 0x2 designated_port 32770 designated_cost 0 designated_bridge 8000.50:0:0:3:0:3 designated_root 8000.50:0:0:3:0:3 hold_timer    0.00 message_age_timer    0.00 forward_delay_timer    0.00 topology_change_ack 0 config_pending 0 proxy_arp off proxy_arp_wifi off mcast_router 1 mcast_fast_leave off mcast_flood on neigh_suppress on group_fwd_mask 0x0 group_fwd_mask_str 0x0 group_fwd_maskhi 0x0 group_fwd_maskhi_str 0x0 vlan_tunnel off isolated off addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

It would be great to have the output like

vxlan id 10010
srcport 0
dstport 4789

I remember a couple of years back Linux system engineers I used to work with doing command | python ... but I was not able to find/recall the command. (I have Python installed).

Any other solutions (especially single liners) are welcome.

  • is that correct, you want srcport 0 and not srcport 0 0?, also these information always appears at 3rd line of the command's output? and format always same (specially for the 3rd line in output) ? – αғsнιη Feb 16 at 16:07
  • source port 0 0 would be fine, something general that will tidy the output would do the trick. yeah mostly the same one key one value – kaya atabey Feb 16 at 16:09
  • Not clear how the two rows before vxlan were discarded, or where the fold should occur: most elements have one word and a value, but there are anomalies like srcport 0 0 and nolearning ttl 64. Values are variously numeric, hex constants, words on off yes no UNKNOWN DEFAULT etc. so detailed rules are needed. – Paul_Pedant Feb 16 at 16:21
  • I assumed you wanted to list all the output realigned: just the four example values you show is rather simpler (and much less interesting). – Paul_Pedant Feb 16 at 16:24


your-command |grep -Eo '(vxlan id|srcport|dstport) [0-9]+|local [0-9.]+'
  • yes this one returned the values i listed and i got the idea thanks alot. – kaya atabey Feb 16 at 16:23
  • If you generalize the values as [^[:blank:]]+ then "local" does not have to be a special case. – glenn jackman Feb 16 at 22:52

This sounds like a job for the fmt command that's part of coreutils.

In particular, you'll want to use

-s, --split-only

split long lines, but do not refill


If your implementation of ip supports the --json output format switch, then I'd suggest something like

sudo ip -d link show vxlan_10 | jq -r '.[] | to_entries[] | "\(.key) \(.value)"'

Ex. (I don't have a vlan interface, so this shows a regular wireless interface):

$ ip --json link show wls1 | jq -r '.[] | to_entries[] | "\(.key) \(.value)"'
ifindex 3
ifname wls1
mtu 1500
qdisc mq
operstate UP
linkmode DORMANT
group default
txqlen 1000
link_type ether
address 00:21:6a:96:40:12
broadcast ff:ff:ff:ff:ff:ff
  • you are right i also did "ip --json link show wls1 | python -m json.tool" this also works if i want them all sorted clean. Thankyou. – kaya atabey Feb 16 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.