You need to enable JavaScript to run this app.
导航

为网卡分配辅助私网IP

最近更新时间2023.08.29 17:05:13

首次发布时间2023.06.09 11:20:33

本文介绍如何为网卡分配一个或多个辅助私网IP。

示例代码

// Example Code generated by Beijing Volcanoengine Technology.

package vpcexample

import (
	"fmt"

	"github.com/volcengine/volcengine-go-sdk/service/vpc"
	"github.com/volcengine/volcengine-go-sdk/volcengine"
	"github.com/volcengine/volcengine-go-sdk/volcengine/credentials"
	"github.com/volcengine/volcengine-go-sdk/volcengine/session"
)

func AssignPrivateIpAddresses() {
  // 设置您的ak、sk、要访问的地域
	ak, sk, region := "Your AK", "Your SK", "Region"
	config := volcengine.NewConfig().
		WithRegion(region).
		WithCredentials(credentials.NewStaticCredentials(ak, sk, ""))
	sess, err := session.NewSession(config)
	if err != nil {
		panic(err)
	}
	svc := vpc.New(sess)

	// 为网卡分配辅助私网IP
	assignPrivateIpAddressesInput := &vpc.AssignPrivateIpAddressesInput{
		NetworkInterfaceId: volcengine.String("eni-bp67acfmxazb4p****"),   // 网卡的ID
		PrivateIpAddress:   volcengine.StringSlice([]string{"192.168.XX.10", "192.168.XX.12"}), // 分配多个私网IP地址
	}

	// 发起请求并处理返回或异常
	resp, err := svc.AssignPrivateIpAddresses(assignPrivateIpAddressesInput)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
}

相关文档