# 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 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命令让配置即时生效
netplan官方文档: https://netplan.io/reference/