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


目录
相关文章
|
2月前
|
网络协议 Java 应用服务中间件
Springboot+ubuntu+Let‘s Encrypt配置https
Springboot+ubuntu+Let‘s Encrypt配置https
33 0
|
2月前
|
Ubuntu
百度搜索:蓝易云【Ubuntu开机自启服务systemd.service配置教程】
现在,你的服务将在Ubuntu开机时自动启动,并在之后的启动中持续运行。记得根据你的实际需求修改 `your_service_name.service`文件中的相关信息。
54 2
|
3月前
|
存储 网络协议 Ubuntu
如何在Ubuntu安装配置SVN服务端并实现无公网ip访问内网资料库
如何在Ubuntu安装配置SVN服务端并实现无公网ip访问内网资料库
69 0
|
3月前
|
Ubuntu 安全 网络安全
百度搜索:蓝易云【Ubuntu系统SSH服务端配置】
现在,你已经成功在Ubuntu系统上配置了SSH服务端。这将允许其他计算机通过SSH协议连接到你的Ubuntu系统,并进行远程管理和操作。请注意,远程访问有安全风险,建议在生产环境中采取必要的安全措施来保护系统。
39 3
|
3月前
|
存储 Ubuntu
百度搜索:蓝易云【在ubuntu系统下安装配置onedrive步骤】
现在,你已经成功在Ubuntu系统下安装和配置了OneDrive,可以使用该工具与OneDrive云端存储进行同步。
40 0
|
3月前
|
Ubuntu 网络协议
百度搜索:蓝易云【ubuntu系统如何设置静态IP地址?】
现在,你已经成功在Ubuntu系统中设置了静态IP地址。系统将使用指定的静态IP地址进行网络连接。
29 0
|
3月前
|
Ubuntu 网络协议 Linux
如何在无公网IP环境使用Windows远程桌面Ubuntu
如何在无公网IP环境使用Windows远程桌面Ubuntu
59 0
|
3月前
|
Ubuntu
百度搜索:蓝易云【Ubuntu系统新增硬盘,配置自动挂载教程】
现在,您的新硬盘应该已经成功配置为开机自动挂载到 `/mnt/new_disk`目录下了。在每次开机后,Ubuntu会自动将该硬盘挂载到指定的挂载点,您可以在该挂载点下访问和使用新硬盘。
38 0
|
2月前
|
负载均衡 Ubuntu 应用服务中间件
|
11天前
|
Ubuntu 开发工具 git
ubuntu18.04下配置muduoC++11环境
以上步骤将在Ubuntu 18.04下配置C++11环境,并编译安装muduo库。请根据实际情况对配置步骤进行调整。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
15 0