ubuntu20配置固定IP地址

搭建了一个本地服务器,在局域网内部署了一些服务,但是路由器重启后,服务器的IP地址有时候会变,这个时候该怎么办呢,如何进行固定IP设置呢?

图形化版

图形化版类似于windows的网络设置,比较简单,此处不做描述。

Server-20版本

  1. 找到yaml文件
ubuntu@ubuntu:~$ cd /etc/netplan/
ubuntu@ubuntu:/etc/netplan$ ll
total 12
drwxr-xr-x   2 root root 4096 Apr  1  2020 ./
drwxr-xr-x 100 root root 4096 May  5 01:32 ../
-rw-r--r--   1 root root  416 Apr  1  2020 50-cloud-init.yaml
  1. 查看
ubuntu@ubuntu:/etc/netplan$ cat 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:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2
  1. 查看网络信息
ubuntu@ubuntu:/etc/netplan$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.xxxx  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 xxxx::xxxx:xxxx:xxxx:xxxx  prefixlen 64  scopeid 0x20<link>
        ether e4:5f:01:00:4d:49  txqueuelen 1000  (Ethernet)
        RX packets 3902  bytes 3716301 (3.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2633  bytes 216207 (216.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  1. 编辑
ubuntu@ubuntu:/etc/netplan$ sudo vi 50-cloud-init.yaml 
network:
    ethernets:
        eth0: # 网卡名称
            addresses: [192.168.0.101/24] # ip地址
            gateway4: 192.168.0.1	# 网关地址
            nameservers:
                    addresses: [8.8.8.8,114.114.114.114] # DNS解析地址
#            dhcp4: true
#            optional: true
    version: 2
    renderer: networkd
  1. 执行
sudo netplan apply

注:其他版本可能不适用该方法。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值