ubuntu 20.04中配置静态IP
2022/5/2 7:13:38
本文主要是介绍ubuntu 20.04中配置静态IP,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、系统
root@liujiaxinpc1:/home/test# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.4 LTS Release: 20.04 Codename: focal
2、查看网卡名称
root@liujiaxinpc1:/home/test# netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ens32 1500 48091 0 0 0 8458 0 0 0 BMRU lo 65536 224 0 0 0 224 0 0 0 LRU
3、修改网络配置文件,保存退出
# This is the network config written by 'subiquity'??? 这个格式贼难调, 可以直接复制这个模板 network: ethernets: ens32: ## 网卡名称 addresses: - 192.168.3.50/24 ## ip地址 gateway4: 192.168.3.1 ## 网关 nameservers: addresses: - 119.29.29.29 ## DNS服务 version: 2
4、将网络模式调整为桥接模式
5、重启网络服务(如果出现报错,一般是网络配置文件格式的问题)
root@liujiaxinpc1:~/Desktop# netplan apply
6、查看ip
root@liujiaxinpc1:~/Desktop# ifconfig | head ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.3.50 netmask 255.255.255.0 broadcast 192.168.3.255 inet6 fe80::1a8b:1520:347d:bea9 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ed:73:9d txqueuelen 1000 (Ethernet) RX packets 49372 bytes 68621721 (68.6 MB) RX errors 0 dropped 239 overruns 0 frame 0 TX packets 8854 bytes 653029 (653.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
7、测试网络
root@liujiaxinpc1:~/Desktop# ping -c 5 www.baidu.com PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data. 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=51 time=17.8 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=51 time=18.2 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=51 time=17.7 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=4 ttl=51 time=17.8 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=5 ttl=51 time=18.0 ms --- www.a.shifen.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4007ms rtt min/avg/max/mdev = 17.713/17.907/18.166/0.164 ms
8、重启观察IP是否发生变化
root@liujiaxinpc1:~/Desktop# reboot
9、查看ip,检查网络连接
root@liujiaxinpc1:~/Desktop# ifconfig | head -n 5 ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.3.50 netmask 255.255.255.0 broadcast 192.168.3.255 inet6 fe80::20c:29ff:feed:739d prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ed:73:9d txqueuelen 1000 (Ethernet) RX packets 40 bytes 2791 (2.7 KB) root@liujiaxinpc1:~/Desktop# ping -c 5 www.baidu.com PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data. 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=51 time=17.8 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=51 time=17.8 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=51 time=17.9 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=4 ttl=51 time=17.7 ms 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=5 ttl=51 time=17.8 ms --- www.a.shifen.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4009ms rtt min/avg/max/mdev = 17.718/17.804/17.893/0.055 ms
没有问题。
这篇关于ubuntu 20.04中配置静态IP的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-01为什么公共事业机构会偏爱 TiDB :TiDB 数据库在某省妇幼健康管理系统的应用
- 2024-04-26敏捷开发:想要快速交付就必须舍弃产品质量?
- 2024-04-26静态代码分析的这些好处,我竟然都不知道?
- 2024-04-26你在测试金字塔的哪一层?(下)
- 2024-04-26快刀斩乱麻,DevOps让代码评审也自动起来
- 2024-04-262024年最好用的10款ER图神器!
- 2024-04-2203-为啥大模型LLM还没能完全替代你?
- 2024-04-2101-大语言模型发展
- 2024-04-17基于SpringWeb MultipartFile文件上传、下载功能
- 2024-04-14个人开发者,Spring Boot 项目如何部署