⽹络配置Netplan-ubuntu18.04⼀、获取当前配置
# part1
NetCardName // ⽹卡名
IP // IPv4/IPv6地址
SubnetMask // IPv4/IPv6⼦⽹掩码
MTU
MAC // MAC地址
# 通过系统调⽤获取,⽤的go原⽣包获取,可以⽤系统命令ifconfig来对⽐查看,如下
security@DEFAULTSTRING:~$ ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.205 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::207:32ff:fe67:b732 prefixlen 64 scopeid 0x20<link>
ether 00:07:32:67:b7:32 txqueuelen 1000 (Ethernet)
RX packets 368485 bytes 26495671 (26.4 MB)
RX errors 0 dropped 85574 overruns 0 frame 0
TX packets 149 bytes 10094 (10.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1280
inet 10.171.16.79 netmask 255.255.255.192 broadcast 10.171.16.127
inet6 fe80::207:32ff:fe67:b733 prefixlen 64 scopeid 0x20<link>
ether 00:07:32:67:b7:33 txqueuelen 1000 (Ethernet)
RX packets 40967901 bytes 49095171879 (49.0 GB)
RX errors 0 dropped 85574 overruns 0 frame 0
ubuntu网络配置TX packets 17850895 bytes 11274497274 (11.2 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# par2
Gateway // IPv4/IPv6⽹关
DHCP // 是否⾃动获取IP地址
DNS // 是否⾃动获取DNS服务器
DNSServer1 // ⾸选DNS服务器
DNSServer2 // 次选DNS服务器
# 通过解析netplan配置⽂件获取, netplan配置⽂件下⾯会展⽰
# part3
SendRate // 发送速率
RecvRate // 接收速率
# 解析系统⽂件/proc/net/dev
# 此⽂件中会实时记录每个⽹卡的发送和接收总byte数,通过两次采集数据并相减,则可以得出发送与接收速率⼆、修改当前配置
# 配置⽂件路径
/etc/netplan/*.yaml
# 配置⽰例
# 表⽰有两个⽹卡enp1s0和enp2s0
# enp1s0:
ipv4地址和⼦⽹掩码为192.168.1.205 255.255.255.0, 可表⽰为192.168.1.205/24 (后端⾃动做转换,前端分开配置) dhcp4为false,表⽰配置为静态ip
⽹关为192.168.0.2
mtu为1500
dns server未配置则表⽰⾃动获取dns
# enp2s0:
ipv4地址和⼦⽹掩码为10.171.16.79 255.255.255.192, 可表⽰为10.171.16.79/26
dhcp4为false,表⽰配置为静态ip
⽹关为10.171.16.65
mtu为800
dns server为8.8.8.8
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
addresses:
- 192.168.1.205/24
dhcp4: false
gateway4: 192.168.0.2
mtu: 1500
enp2s0:
addresses:
- 10.171.16.79/26
dhcp4: false
gateway4: 10.171.16.65
mtu: 800
nameservers:
addresses: [8.8.8.8]
# 修改完配置可以⽤sudo netplan apply命令让配置即时⽣效
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论