
本次配置中 :
主网卡IP:172.21.96.85
辅助网卡IP:172.21.96.9
系统版本:Ubuntu Server 22.04 LTS 64位
1. 以管理员身份 登录云服务器,执行以下命令,查看需配置的网卡信息,如图所示,需配置的网卡名称为 eth1:

2. 执行以下命令,进入/etc/netplan/文件夹:
cd /etc/netplan && ls
# 有个 50-cloud-init.yaml 文件
root@VM-96-85-ubuntu:/etc/netplan# ls
00-installer-config.yaml 50-cloud-init.yaml3. 输入命令修改50-cloud-init.yaml配置文件内容:
#修改前先备份下原文件到root目录
cp 50-cloud-init.yaml /root/
#然后修改为如下内容,其实就是追加eth1相关的配置,这里我们采用dhcp的方式,内容如下:
root@VM-96-85-ubuntu:/etc/netplan# cat 50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
eth0:
dhcp4: true
match:
macaddress: 52:54:00:0d:79:0c
set-name: eth0
eth1:
dhcp4: true
match:
macaddress: 20:90:6f:d4:3b:92
set-name: eth1
# 一定要注意缩进对齐关系
4. 配置完成后,输入以下命令,使配置生效。
netplan apply5. 验证配置是否成功,也可以从其他机器ping测。
curl --interface 172.21.96.85 ifconfig.me
curl --interface 172.21.96.9 ifconfig.me
至此,配置完成。
Ubuntu系统配置比较简介,但可能大家实际过程中可能还会遇到各种问题,建议具体问题具体对待,遇事不要钻牛角尖。
另外这里附上静态IP配置方式,生产环境中不建议用静态IP:
network:
version: 2
ethernets:
eth0:
addresses:
- 172.21.96.85/20
match:
macaddress: 52:54:00:0d:79:0c
set-name: eth0
routes:
- to: default
via: 172.21.96.1
metric: 100
routing-policy:
- from: 172.21.96.85
eth1:
addresses:
- 172.21.96.9/20
match:
macaddress: 20:90:6f:d4:3b:92
set-name: eth1
routes:
- to: default
via: 172.21.96.1
metric: 101
routing-policy:
- from: 172.21.96.9文档如有疏漏或者错别字,请评论留言,看见后会修改的。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。