ubuntu开机启动网络配置 - systemd-networkd或netplan

欢迎淘宝搜索飞灵科技,我司相关新产品陆续上线。

手头的开发板有两个网口,网口eth0做IEEE 1588时钟同步,eth1做管理网口。所以期望对这两个网口的开机启动配置是,

  • eth0只要up起来,不用配置IP
  • eth1动态获取IP 在这里插入图片描述

可以使用systemd-networkd或者netplan。

systemd-networkd

编辑配置文件
使用帮助可参考:http://manpages.ubuntu.com/manpages/bionic/man5/systemd.network.5.html

root@TSync:~# cat /etc/systemd/network/50-static.network
[Match]
Name=eth0
root@TSync:~# cat /etc/systemd/network/80-dhcp.network
[Match]
Name=eth1

[Network]
DHCP=yes

开机使能service

root@TSync:~# systemctl enable systemd-networkd.service

netplan

当前开发板的ubuntu版本是18.04.5 LTS,我们使用netplan配置开机启动的网络配置。在安装netplan之前,因为觉得默认的ubuntu软件源下载速度太慢,所以提前替换成清华的ubuntu软件源。可以参考之前的文章“国内ubuntu软件源”。
安装netplan

root@TSync:~# apt install netplan.io

添加配置文件
更多配置文件的写法可以参考官方文档: https://netplan.io/examples/

root@TSync:~# cat /etc/netplan/0001-eth0-eth1.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth1:
      dhcp4: true
    eth0:
      addresses:
        - 0.0.0.0/24

重启测试

root@TSync:~# ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 0a:7c:9b:05:dc:c8  txqueuelen 1000  (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

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.100  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::44d5:2dff:fef4:2f84  prefixlen 64  scopeid 0x20<link>
        ether 46:d5:2d:f4:2f:84  txqueuelen 1000  (Ethernet)
        RX packets 12  bytes 1806 (1.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17  bytes 1797 (1.7 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 4  bytes 348 (348.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 348 (348.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值