ubuntu server更改IP地址

1.查看网卡信息

ifconfig

如果显示没有这个命令就使用以下命令来进行安装

sudo apt-get install net-tools

我习惯使用net-tools,也可以使用其他命令

ip addr show

ifconfig命令输出如下



eno3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.x.x  netmask 255.255.255.0  broadcast 192.168.x.x
        inet6 fd6e:x  prefixlen 128  scopeid 0x0<global>
        inet6 fd6e:x  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::x  prefixlen 64  scopeid 0x20<link>
        ether 24:x  txqueuelen 1000  (Ethernet)
        RX packets 684  bytes 254271 (254.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 505  bytes 88140 (88.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0x92a80000-92afffff

eno4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.x.x netmask 255.255.255.0  broadcast 192.168.x.x
        inet6 fd6e:x  prefixlen 128  scopeid 0x0<global>
        inet6 fe80::x  prefixlen 64  scopeid 0x20<link>
        inet6 fd6e:x  prefixlen 64  scopeid 0x0<global>
        ether 24:x  txqueuelen 1000  (Ethernet)
        RX packets 119  bytes 11669 (11.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56  bytes 6017 (6.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0x92a00000-92a7ffff

这里我屏蔽了一部分内容,只保留了网卡3和网卡4的。

2.确认IP配置文件

ls /etc/netplan

输出结果如下

xxxx@xxxx:~$ ls /etc/netplan/
50-cloud-init.yaml

50-cloud-init.yaml为IP配置文件,所以要修改这个配置文件,不同版本的文件不一定为这个名字

3.修改配置文件

这里我要将动态改为静态.。

ip:192.168.5.12

DNS:8.8.8.8

子网掩码:255.255.255.0

网关:192.168.5.1

使用以下命令进行修改

sudo vi /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:
    ethernets:
        eno1:
            dhcp4: true
        eno2:
            dhcp4: true
        eno3:
          addresses: [192.168.5.12/24 ]
          optional: true
          gateway4: 192.168.5.1
          nameservers:
            addresses: [8.8.8.8]
        eno4:
            dhcp4: true
    version: 2

修改后保存

4.验证IP方案正确性

输入以下命令

sudo netplan try

等待一段时间。

5.应用IP方案

sudo netplan apply

6.重新验证IP地址

ifconfig

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值