嵌入式爱好者

OK1028使用systemd工具创建永久网桥

2021-7-20 18:16| 发布者: djh| 查看: 1181| 评论: 0|原作者: djh

类目: 知识库  >  LS1012A/LS1043A/LS1046A系列产品     文档编号: 523

systemd工具创建永久网桥

vi /etc/systemd/network/br0.netdev

填写以下内容:

[NetDev]

Name=br0

Kind=bridge

vi /etc/systemd/network/br0.network

填写以下内容:

[Match]

Name=br0

KernelCommandLine=!root=/dev/nfs

[Network]

Address=172.16.0.1/24

2. 绑定网口到网桥上,这里将swp0swp1swp2swp3加入到br0中。需要分别 创建对应的4个文件。

touch /etc/systemd/network/swp0.network

touch /etc/systemd/network/swp1.network

touch /etc/systemd/network/swp2.network

touch /etc/systemd/network/swp3.network

 每个文件的内容和如下swp0.network内容类似,但是 [Name=swp0] 属性不一样,要和文件名对应。

 swp0.network

 

[Match]

Name=swp0 

KernelCommandLine=!root=/dev/nfs

[Network]

Bridge=br0

 

3、将br0设置为静态IP

touch /etc/network/inte**ce.d/br0

 

auto br0

iface br0  inet static

address 172.16.0.1

 

4、在脚本中添加重启网络服务命令(红色字体):

 vim lib/systemd/system/ifup@.service

 

 

[Unit]

Description=ifup for %I

After=local-fs.target network-pre.target apparmor.service systemd-sysctl.service

Before=network.target shutdown.target network-online.target

BindsTo=sys-subsystem-net-devices-%i.device

After=sys-subsystem-net-devices-%i.device

DefaultDependencies=no

IgnoreOnIsolate=yes

 

[Service]

# avoid stopping on shutdown via stopping system-ifup.slice

Slice=system.slice

ExecStart=/bin/sh -ec 'ifup --allow=hotplug %I; ifup --allow=auto %I; \

    if ifquery %I >/dev/null; then ifquery --state %I >/dev/null; systemctl restart systemd-networkd.service; fi'

ExecStop=/sbin/ifdown %I

RemainAfterExit=true

TimeoutStartSec=5min

 

reboot重启

Ifconfig 查看节点:


已解决

未解决

只是看看

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-12-22 18:29

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部