【Ubuntu server18.04 】使用netplan配置静态IP
1. 查看本机ip
$ ifconfig docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:97:70:eb:98 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.193.131 netmask 255.255.255.0 broadcast 192.168.193.255 inet6 fe80::20c:29ff:fe6e:f773 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:6e:f7:73 txqueuelen 1000 (Ethernet) RX packets 740 bytes 71366 (71.3 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 440 bytes 57899 (57.8 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 92 bytes 7100 (7.1 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 92 bytes 7100 (7.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2. 查看本机网关
$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.193.2 0.0.0.0 UG 0 0 0 ens33 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 192.168.193.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
3. 编辑netplan默认配置文件
sudo vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity' network: ethernets: ens33: dhcp4: no addresses: [192.168.193.131/24] gateway4: 192.168.193.2 nameservers: addresses: [192.168.193.2] version: 2
4. 应用配置
$ sudo netplan apply
5. 检查连通性
ping 192.168.193.131
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?