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


陈骄
+关注
目录
打赏
0
0
0
0
10
分享
相关文章
|
8天前
|
Ubuntu下载工具:ip addr、ifconfig、ping、make的使用
的选项和参数,这里只是简单地介绍了它们的基本用法。如果你想要深入学习这些工具,我建议你查阅它们的man页面,或者找一本好的Linux教程进行学习。
64 22
在Ubuntu系统下使用vsftpd配置FTP服务器的步骤
以上就是在Ubuntu系统下使用vsftpd配置FTP服务器的步骤。这些步骤都是基础的,但足够让你建立一个简单的FTP服务器。如果你需要更高级的功能,例如SSL加密、虚拟用户等,你可能需要进一步研究vsftpd的配置选项。
57 13
在Ubuntu 18.04服务器上配置双网口以接入互联网
总结一下,配置双网口在Ubuntu 18.04服务器就像一场冒险游戏,你小心翼翼地从查看网络布局开始,铺设新线路,最后得到了通往互联网的双重通道。祝你在网络世界的冒险旅程中更上一层楼!
57 11
在 Ubuntu 20.04 上安装和配置 Redis
在 Ubuntu 20.04 上安装和配置 Redis 的步骤如下:首先更新系统包,然后通过 `apt` 安装 Redis。安装后,启用并启动 Redis 服务,检查其运行状态。可选配置包括修改绑定 IP、端口等,并确保防火墙设置允许外部访问。最后,使用 `redis-cli` 测试 Redis 功能,如设置和获取键值对。
65 1
ubuntu/debian shell 脚本自动配置 gitea git 仓库
这是一个自动配置 Gitea Git 仓库的 Shell 脚本,支持 Ubuntu 20+ 和 Debian 12+ 系统。脚本会创建必要的目录、下载并安装 Gitea,创建 Gitea 用户和服务,确保 Gitea 在系统启动时自动运行。用户可以选择从官方或小绿叶技术博客下载安装包。
212 2
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
210 3
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
Ubuntu22.04静态ip配置+yarn build后显示内存超限,变异失败
Ubuntu22.04静态ip配置+yarn build后显示内存超限,变异失败
86 2
Ubuntu22.04静态ip配置+yarn build后显示内存超限,变异失败
Linux/Ubuntu下使用VS Code配置C/C++项目环境调用OpenCV
通过以上步骤,您已经成功在Ubuntu系统下的VS Code中配置了C/C++项目环境,并能够调用OpenCV库进行开发。请确保每一步都按照您的系统实际情况进行适当调整。
1315 3
liunx各大发行版(centos,rocky,ubuntu,国产麒麟kylinos)网卡配置和包管理方面的区别
liunx各大发行版(centos,rocky,ubuntu,国产麒麟kylinos)网卡配置和包管理方面的区别
268 0