[comment]: # ({2898fc4b-2898fc4b})
# hostinterface.replacehostinterfaces

[comment]: # ({/2898fc4b-2898fc4b})

[comment]: # ({e440e997-f14e7778})
### 描述

```
object hostinterface.replacehostinterfaces(object parameters)
```

此方法允许替换给定 主机 上的所有 主机 接口。

::: noteclassic
此方法仅对 *Admin* 和 *Super admin* 用户类型可用。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见 [User
roles](/manual/web_interface/frontend_sections/users/user_roles)。
:::

[comment]: # ({/e440e997-f14e7778})

[comment]: # ({ad328eba-f5cf0b40})
### 参数

`(object)` 包含要更新的主机 ID 和新主机接口的参数。

|Parameter|[Type](/manual/api/reference_commentary#data-types)|Description|
|--|--|------|
|interfaces|object/array|用于替换当前主机接口的[主机接口](/manual/api/reference/hostinterface/object)。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior):<br>- *required*|
|hostid|ID|要更新的主机 ID。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior):<br>- *required*|

[comment]: # ({/ad328eba-f5cf0b40})

[comment]: # ({88283807-88283807})
### 返回值

`(object)` 返回一个 object，其中包含在 `interfaceids` 属性下列出的新建 主机 接口的 ID。

[comment]: # ({/88283807-88283807})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({01fd5e38-98e67db1})
#### 替换主机接口

将所有 主机 接口替换为单个 agent 接口。

[执行请求](/manual/api#执行请求):


```json
{
    "jsonrpc": "2.0",
    "method": "hostinterface.replacehostinterfaces",
    "params": {
        "hostid": "30052",
        "interfaces": {
            "dns": "",
            "ip": "127.0.0.1",
            "main": 1,
            "port": "10050",
            "type": 1,
            "useip": 1
        }
    },
    "id": 1
}
```
响应:


```json
{
    "jsonrpc": "2.0",
    "result": {
        "interfaceids": [
            "30081"
        ]
    },
    "id": 1
}
```

[comment]: # ({/01fd5e38-98e67db1})

[comment]: # ({272c42ef-272c42ef})
### 另请参阅

-   [host.update](/manual/api/reference/host/update)
-   [host.massupdate](/manual/api/reference/host/massupdate)

[comment]: # ({/272c42ef-272c42ef})

[comment]: # ({9d1e0b55-9d1e0b55})
### 来源

CHostInterface::replaceHostInterfaces() 函数位于
*ui/include/classes/api/services/CHostInterface.php* 文件中。

[comment]: # ({/9d1e0b55-9d1e0b55})
