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-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南