ubuntun20.4.3配置静态ip - netplan

本文详细介绍如何在Ubuntu系统中配置静态IP地址,包括配置步骤、注意事项及验证方法。

ubuntu 配置静态IP

一般在安装ubuntu虚拟机后我们默认使用dhcp获取ip,在虚拟机重启后ip地址可能会修改掉,所以设置成静态ip防止ip变更,影响本地相关的一些ip设置和ssh连接工具的连接

netplan

配置静态ip准备

1、非root用户下需要加sudo执行
2、确定所配置的静态ip在局域网中是否已被实用
ping xx.xx.xx.xx
ubuntu@ubuntu:~$ ping 192.168.3.251
PING 192.168.3.251 (192.168.3.251) 56(84) bytes of data.
无法接收到任何数据包,ip未被占用,可以设置静态ip
目录介绍
/etc/netplan 网络配置目录
文件介绍
00-installer-config.yaml  网络配置文件
初始文件内容
# This is the network config written by 'subiquity'
#network:
#  ethernets:
#    enp0s5: //网络接口名
#      dhcp4: true  //是否开启dhcp4(ipv4)  true开启
#  version: 2

配置静态ip,建议将原有配置注释掉后修改

# This is the network config written by 'subiquity'
#network:
#  ethernets:
#    enp0s5:
#      dhcp4: true  
#  version: 2
network:
  ethernets:
    enp0s5: 
      addresses:   //静态ip
      - 192.168.3.251/24
      gateway4: 192.168.3.1 //网关
      nameserver:  //域名服务器
        addresses: 
        - 114.114.114.114
        - 8.8.8.8
        search:
        - 114.114.114.114
        - 8.8.8.8
  version: 2

使网络配置生效

netplan apply

生效后验证是否成功

ubuntu@ubuntu:~$ ifconfig
enp0s5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.251  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::21c:42ff:fe57:3d9a  prefixlen 64  scopeid 0x20<link>
        ether 00:1c:42:57:3d:9a  txqueuelen 1000  (Ethernet)
        RX packets 56938  bytes 5646565 (5.6 MB)
        RX errors 0  dropped 33576  overruns 0  frame 0
        TX packets 1301  bytes 342502 (342.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 100  bytes 7908 (7.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 100  bytes 7908 (7.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

配置完成后 ping检查一下网关和www.baidu.com是否能够ping通,如果可以表示静态ip配置成功至此完成了修改

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值