ubuntu2204使用netplan配置网络信息


前言

ubuntu2204操作系统通过netplan配置网络信息
配置文件:/etc/netplan/00-installer-config.yaml
命令工具:netplan


一、使用dhcp方式配置

network:
  ethernets:
    ens3:
      dhcp4: true
  version: 2

在这里插入图片描述

备注:要注意冒号后面要带一个空格,在使用编辑器编辑的时候,要注意格式。

二、使用手动配置方式

配置信息:

  • IP:192.168.150.55
  • NETMASK:24
  • 网关:192.168.150.254
  • DNS:114.114.114.114, 8.8.8.8
network:
  ethernets:
    ens3:
      addresses: [192.168.150.55/24]          # 设置静态IP地址和掩码
      gateway4: 192.168.150.254                # 设置网关地址
      dhcp4: false                            # 禁用dhcp
      nameservers:
        addresses: [114.114.114.114, 8.8.8.8] # 设置主、备DNS
  version: 2

使用命令使得配置信息生效

查看命令信息

root@ubuntu:~# sudo netplan --help
usage: /usr/sbin/netplan  [-h] [--debug]  ...

Network configuration in YAML

options:
  -h, --help  show this help message and exit
  --debug     Enable debug messages

Available commands:
  
    help      Show this help message
    apply     Apply current netplan config to running system
    generate  Generate backend specific configuration files from /etc/netplan/*.yaml
    get       Get a setting by specifying a nested key like "ethernets.eth0.addresses", or "all"
    info      Show available features
    ip        Retrieve IP information from the system
    set       Add new setting by specifying a dotted key=value pair like ethernets.eth0.dhcp4=true
    rebind    Rebind SR-IOV virtual functions of given physical functions to their driver
    status    Query networking state of the running system
    try       Try to apply a new netplan config to running system, with automatic rollback

执行更新

sudo netplan apply

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值