Ubuntu配置静态IP地址

简介: Ubuntu配置静态IP地址

配置静态地址的方法

图形界面配置

略(主要是需要截图好几张,但是本身操作又简单就不写了)

修改配置文件

配置文件路径在/etc/netplan/xxx.yaml(这里每个人的xxx可能不一样)

默认如果开启了dhcp自动获取地址的话应该是这样

root@Ubuntu:~# cat /etc/netplan/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:
        ens3:
            dhcp4: true
            match:
                macaddress: fa:16:3e:20:57:4e
            mtu: 1500
            set-name: ens3

如果需要修改为静态地址可以先找出当前IP然后配置为一样的

root@Ubuntu:~# ip a |grep "global.*ens3" #这里的ens3是对应的网卡名
    inet 10.10.21.170/24 brd 10.10.21.255 scope global dynamic ens3

接下来就是将配置文件的IP修改为10.10.21.170/24

root@Ubuntu:~# cat /etc/netplan/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:
        ens3:
            dhcp4: false  #这里也可以写no
            addresses: [10.10.21.170/24]  
            optional: true
            gateway4: 10.10.21.254
            nameservers:
              addresses: [223.5.5.5]
            match:
              macaddress: fa:16:3e:20:57:4e
            mtu: 1500
            set-name: ens3
root@Ubuntu:~# netplan apply

NetworkManager修改

如果没有命令的话需要先安装NetworkManager

root@Ubuntu:~# apt-get install network-manager

接下来启动NetworkManager管理网卡

修改NewworkManager配置文件

root@Ubuntu:~# cat /etc/NetworkManager/NetworkManager.conf 
[main]
plugins=ifupdown,keyfile
[ifupdown]
managed=true  #这里默认是false,需要修改为true
[device]
wifi.scan-rand-mac-address=no

修改/etc/netplan/50-cloud-init.yaml

root@Ubuntu:~# cat /etc/netplan/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
  renderer: NetworkManager  #必须修改否则NetworkManager无法管理

修改完成之后重启服务

root@Ubuntu:~# systemctl restart network-manager
root@Ubuntu:~# nmcli device 
DEVICE        TYPE      STATE      CONNECTION 
ens13         ethernet  connected  ens3.1          
ens3          ethernet  connected  ens3       
如果上面没有改的话,这里的state会是unmanaged

nmtui修改

这种也是类图形界面

root@Ubuntu:~# nmtui

8e4f8000308444ab9be2b751c58b9f0d.png

然后按提示一步步修改即可,修改完了记得activate激活配置

nmcli

命令行修改

root@Ubuntu:~# nmcli connection modify ens3.1 ipv4.addresses 10.10.30.28/24 ipv4.gateway 10.10.30.254 ipv4.method manual ipv4.dns 114.114.114.114 autoconnect yes
root@Ubuntu:~# nmcli connection up ens3.1 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

nmcli修改网卡名字

很多时候用来NetworkManager会生成一些奇奇怪怪的网卡名字,比如"Wired connection 1",看起来就难受,用起来有时候也不方便

root@Ubunt:~# nmcli connection modify "Wired connection 1" connection.id ens33


目录
相关文章
|
9天前
|
网络协议 Ubuntu 网络安全
|
14天前
|
消息中间件 监控 Ubuntu
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
47 3
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
|
18天前
|
资源调度
Ubuntu22.04静态ip配置+yarn build后显示内存超限,变异失败
Ubuntu22.04静态ip配置+yarn build后显示内存超限,变异失败
31 2
Ubuntu22.04静态ip配置+yarn build后显示内存超限,变异失败
|
9天前
|
Ubuntu Linux 编译器
Linux/Ubuntu下使用VS Code配置C/C++项目环境调用OpenCV
通过以上步骤,您已经成功在Ubuntu系统下的VS Code中配置了C/C++项目环境,并能够调用OpenCV库进行开发。请确保每一步都按照您的系统实际情况进行适当调整。
114 3
|
1月前
|
Ubuntu 网络安全 开发工具
Ubuntu19.04的安装过程详解以及操作系统初始化配置
本文详细介绍了Ubuntu 19.04操作系统的安装过程、初始化配置、网络设置、软件源配置、SSH远程登录以及终端显示设置。
72 1
Ubuntu19.04的安装过程详解以及操作系统初始化配置
|
1月前
|
存储 Prometheus 监控
在Ubuntu系统上安装与配置Prometheus的步骤
通过以上步骤,您应该已经成功在Ubuntu系统上安装并配置了Prometheus。您现在可以开始使用Prometheus收集和分析您的系统和应用程序的指标数据了。
83 1
|
20天前
|
Ubuntu 网络协议 Linux
liunx各大发行版(centos,rocky,ubuntu,国产麒麟kylinos)网卡配置和包管理方面的区别
liunx各大发行版(centos,rocky,ubuntu,国产麒麟kylinos)网卡配置和包管理方面的区别
|
1月前
|
Ubuntu Oracle 关系型数据库
Oracle VM VirtualBox之Ubuntu 22.04LTS双网卡网络模式配置
这篇文章是关于如何在Oracle VM VirtualBox中配置Ubuntu 22.04LTS虚拟机双网卡网络模式的详细指南,包括VirtualBox网络概述、双网卡网络模式的配置步骤以及Ubuntu系统网络配置。
108 3
|
1月前
|
Ubuntu 开发工具 虚拟化
MacOS系统基于VMware Fusion配置Ubuntu 22.04LTS环境
这篇文章介绍了如何在MacOS系统上使用VMware Fusion虚拟化软件配置Ubuntu 22.04 LTS环境,包括自定义VMware Fusion网段、Ubuntu系统安装、配置root用户登录、设置静态IP地址、修改默认网卡名称、配置PS1变量、设置登录界面为字符界面、修改软件源和进行vim基础优化等步骤。
198 2
|
1月前
|
Ubuntu
树莓派 —— ubuntu上通过netplan配置网络
树莓派 —— ubuntu上通过netplan配置网络