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配置成功至此完成了修改
本文详细介绍如何在Ubuntu系统中配置静态IP地址,包括配置步骤、注意事项及验证方法。
8059

被折叠的 条评论
为什么被折叠?



