ubuntu18.04以上版本配置多ip

各系统都有不同的配置方案,

这个是yaml格式的配置,可以和json转换,所以你可以用熟悉的json先写好。

再找工具转成yaml

http://www.json2yaml.com/

https://oktools.net/json2yaml

这里是在线工具

系统默认DHCP单ip的配置如下

{
  "network": {
    "version": 2,
    "ethernets": {
      "eth0": {
        "dhcp4": true
      }
    }
  }
}

单ip静态ip地址json格式

{
  "network": {
    "version": 2,
    "ethernets": {
      "eth0": {
        "dhcp4": false,
        "dhcp6": false,
        "addresses": [
          "192.168.31.2/24"
        ],
        "gateway4": "192.168.31.1",
        "nameservers": {
          "search": [
            "mydomain",
            "otherdomain"
          ],
          "addresses": [
            "114.114.114.114",
            "1.1.1.1"
          ]
        }
      }
    }
  }
}

双IP的DHCP配置如下

{
  "network": {
    "version": 2,
    "ethernets": {
      "eth0": {
        "dhcp4": true,
        "dhcp4-overrides": {
          "route-metric": 100
        }
      },
      "eth1": {
        "dhcp4": true,
        "dhcp4-overrides": {
          "route-metric": 200
        }
      }
    }
  }
}

连接开放的 WiFi(无密码)

{
  "network": {
    "version": 2,
    "wifis": {
      "eth0": {
        "access-points": {
          "opennetwork": {
          }
        },
        "dhcp4": true
      }
    }
  }
}

连接 WPA 加密的 WiFi

{
  "network": {
    "version": 2,
    "renderer": "networkd",
    "wifis": {
      "eth0": {
        "dhcp4": false,
        "dhcp6": false,
        "addresses": [
          "192.168.31.2/24"
        ],
        "gateway4": "192.168.31.1",
        "nameservers": {
          "addresses": [
            "114.114.114.114",
            "8.8.8.8"
          ]
        },
        "access-points": {
          "network_ssid_name": {
            "password": "mimamima"
          }
        }
      }
    }
  }
}

在单网卡上使用多个 IP 地址(同一网段)

{
  "network": {
    "version": 2,
    "renderer": "networkd",
    "ethernets": {
      "eth0": {
        "addresses": [
          "192.168.31.2/24",
          "192.168.31.3/24"
        ],
        "gateway4": "192.168.31.1"
      }
    }
  }
}

在单网卡使用多个不同网段的 IP 地址

{
  "network": {
    "version": 2,
    "renderer": "networkd",
    "ethernets": {
      "eth0": {
        "addresses": [
          "192.168.31.2/24",
          "192.168.32.2/24",
          "192.168.33.2/24"
        ],
        "routes": [
          {
            "to": "0.0.0.0/0",
            "via": "192.168.31.1",
            "metric": 100
          },
          {
            "to": "0.0.0.0/0",
            "via": "192.168.32.1",
            "metric": 100
          },
          {
            "to": "0.0.0.0/0",
            "via": "192.168.33.1",
            "metric": 100
          }
        ]
      }
    }
  }
}

一个DHCP,另一个静态

寻找中

另外一种写法

寻找中

更多配置请参考

https://netplan.io/examples/

附在线ping工具

https://networkappers.com/tools/ping-tool

https://www.wormly.com/test-remote-ping/host/

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注