iproute2 - ip addr json 导入

iproute2 - ip addr json 导入

我可以使用以下命令从网络配置中获取 json 导出:

ip --json addr show

结果:

[
  {
    "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
      }
    ]
  }
]

如何以 JSON 格式导入网络配置?我知道有些选项不可配置,例如"valid_life_time":4294967295

我想配置我的 IP 地址和其他可配置选项

我用的是 debian,不是 ubuntu。

相关内容