简单配置Ubuntu修改固定IP
2023-04-22 本文已影响0人
不可思议的黄老师
1、查看网卡信息 ifconfig
,系统分配的IP地址 192.168.0.104
,注意自身网络的网关
Last login: Thu Apr 13 08:39:14 2023 from 192.168.0.100
root@huang:~# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.104 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::a00:27ff:fe0c:abe5 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:0c:ab:e5 txqueuelen 1000 (Ethernet)
RX packets 67324 bytes 94714303 (94.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22006 bytes 1602508 (1.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、备份后编辑 /etc/netplan/00-installer-config.yaml
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
sudo vi /etc/netplan/00-installer-config.yaml
3、修改配置
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3: #要修改的网卡
dhcp4: no #不自动分配IP
addresses: [192.168.0.140/24] #配置IP地址
gateway4: 192.168.0.1 #配置网关
nameservers:
addresses: [192.168.0.1] #DNS服务器地址,多个DNS服务器地址需要用英文逗号分隔开
version: 2
4、应用配置
sudo netplan apply
5、测试网络 ping baidu.com
或者 curl -i baidu.com
root@huang:~# curl -i baidu.com
HTTP/1.1 200 OK
Date: Sun, 23 Apr 2023 02:14:49 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Mon, 24 Apr 2023 02:14:49 GMT
Connection: Keep-Alive
Content-Type: text/html
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>