0

I can get a json export from my network configuration with following command:

ip --json addr show

result:

[
  {
    "ifindex": 1,
    "ifname": "lo",
    "flags": [
      "LOOPBACK",
      "UP",
      "LOWER_UP"
    ],
    "mtu": 65536,
    "qdisc": "noqueue",
    "operstate": "UNKNOWN",
    "group": "default",
    "txqlen": 1000,
    "link_type": "loopback",
    "address": "00:00:00:00:00:00",
    "broadcast": "00:00:00:00:00:00",
    "addr_info": [
      {
        "family": "inet",
        "local": "127.0.0.1",
        "prefixlen": 8,
        "scope": "host",
        "label": "lo",
        "valid_life_time": 4294967295,
        "preferred_life_time": 4294967295
      }
    ]
  },
  {
    "ifindex": 2,
    "ifname": "wlan0",
    "flags": [
      "BROADCAST",
      "MULTICAST",
      "UP",
      "LOWER_UP"
    ],
    "mtu": 1500,
    "qdisc": "mq",
    "operstate": "UP",
    "group": "default",
    "txqlen": 1000,
    "link_type": "ether",
    "address": "40:a3:cc:b5:12:c9",
    "broadcast": "ff:ff:ff:ff:ff:ff",
    "addr_info": [
      {
        "family": "inet",
        "local": "192.168.0.137",
        "prefixlen": 24,
        "broadcast": "192.168.0.255",
        "scope": "global",
        "dynamic": true,
        "noprefixroute": true,
        "label": "wlan0",
        "valid_life_time": 4462,
        "preferred_life_time": 4462
      },
      {
        "family": "inet6",
        "local": "fe80::42a3:ccff:feb5:12c9",
        "prefixlen": 64,
        "scope": "link",
        "noprefixroute": true,
        "valid_life_time": 4294967295,
        "preferred_life_time": 4294967295
      }
    ]
  }
]

How can I import my network configuration in JSON format? I know some options are not configurable like "valid_life_time":4294967295

I want configure my ip address and other configurable options

I'm using debian and not ubuntu.

  • I think you have to write a python script. – PersianGulf Apr 25 at 18:43
  • Thanks, yes that's what i'm doing for now, but i was wondering if could do that without any interpreter and i don't have time to using LINUX API with C. that's why i asked this question in here. – Rasool Ziafaty Apr 25 at 19:29
  • Use ifquery instead of ip : /sbin/ifquery {lo,wlan0} --format=json (from ifupdown2 package) ifquery will read the interfaces then print into json format using the --format=json option. – GAD3R Apr 25 at 19:52
  • Thank you GAD3R for your response but ifquery can dump information in JSON format and i can't use this for importing my network configuration in JSON format. would you give us a little more information and an example please? – Rasool Ziafaty Apr 25 at 20:08

Your Answer

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

Browse other questions tagged or ask your own question.