Skip to main content
Version: 1.5.0

五、网络配置

5.1 获取 IP 地址

系统默认使用 DHCP 自动获取 IP 地址。如需获取设备的 IP 地址,请使用 ifconfig 命令:

root@taco-dk:~# ifconfig
...
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.220 netmask 255.255.254.0 broadcast 192.168.57.255
inet6 fe80::ffcb:7fab:c1f1:7ba prefixlen 64 scopeid 0x20<link>
ether ea:97:b3:36:a8:8a txqueuelen 1000 (Ethernet)
RX packets 261813 bytes 88985717 (88.9 MB)
RX errors 1023 dropped 9198 overruns 0 frame 1023
TX packets 66161 bytes 4517331 (4.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 32
...

此时 eth1 的 IP 地址为 192.168.56.220

5.2 配置静态 IP

在配置静态 IP 之前,需要选择一个未被使用的 IP 地址,可以通过 ping 命令检查某个 IP 地址是否已经被使用。

如需手动配置静态 IP,请修改 /etc/netplan/01-network-manager-all.yaml 配置文件。以下是一个示例配置文件:

network:
version: 2
renderer: NetworkManager
ethernets:
eth1:
dhcp4: no
addresses:
- 192.168.56.4/24
optional: yes
dhcp-identifier: mac
routes:
- to: default
via: 192.168.57.254
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
eth3:
dhcp4: no
addresses:
- 192.168.56.5/24
optional: yes
dhcp-identifier: mac
routes:
- to: default
via: 192.168.57.254
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4

保存文件后,执行以下命令应用配置:

netplan apply

这将为 eth1 和 eth3 配置静态 IP 地址。

5.3 验证配置

可通过 ifconfig 命令查看配置文件中定义的 IP 地址是否已激活。

5.4 动态 IP 配置

设置动态 IP 之前,需要先将 /etc/netplan/01-network-manager-all.yaml 文件中的静态 IP 配置注释掉,然后再进行配置:

network:
version: 2
renderer: NetworkManager
# ethernets:
# eth1:
# dhcp4: no
# addresses:
# - 192.168.56.4/24
# optional: yes
# dhcp-identifier: mac
# routes:
# - to: default
# via: 192.168.57.254
# nameservers:
# addresses:
# - 8.8.8.8
# - 8.8.4.4
# eth3:
# dhcp4: no
# addresses:
# - 192.168.56.5/24
# optional: yes
# dhcp-identifier: mac
# routes:
# - to: default
# via: 192.168.57.254
# nameservers:
# addresses:
# - 8.8.8.8
# - 8.8.4.4

使用系统命令训练 ETH PHY 参数,具体步骤如下:

  1. 执行 tps-eth --list 查询系统识别的网络:
root@taco-dk:~# tps-eth --list
Net name needed to adjust delay line:
eth1
eth3
  1. 选择训练某个 ETH 网口:
root@taco-dk:~# tps-eth eth1
MAC: a6:fa:7d:47:ee:62
Speed: 1000Mbps
Elapsed time: 3126 ms
Continuous cnt and location, tx: 58 71, rx: 47 46
Proper tx and rx: 42, 22
  1. 输入 systemctl restart NetworkManager 来立即获取 IP,使用 ifconfigip a 命令检查 IP 地址:
root@taco-dk:~# systemctl restart NetworkManager
root@taco-dk:~# ifconfig
eth1: flags=4163 mtu 1500
inet 192.168.56.220 netmask 255.255.254.0 broadcast 192.168.57.255
inet6 fe80::ffcb:7fab:c1f1:7ba prefixlen 64 scopeid 0x20
ether ea:97:b3:36:a8:8a txqueuelen 1000 (Ethernet)
RX packets 261813 bytes 88985717 (88.9 MB)
RX errors 1023 dropped 9198 overruns 0 frame 1023
TX packets 66161 bytes 4517331 (4.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 32