Add macvlan net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[Unit]
Description=Script to enable macvlan on boot

[Service]
Type=oneshot
ExecStartPre=-/usr/bin/bash -c 'mount --make-rshared /' # for k3s in lxc (optional)
ExecStartPre=-/usr/bin/bash -c '/usr/bin/ip link del mac0'
ExecStartPre=/usr/bin/bash -c '/usr/bin/ip link set eth0 up'
ExecStartPre=/usr/bin/bash -c '/usr/bin/ip link add link eth0 mac0 type macvlan mode bridge'
ExecStartPre=/usr/bin/bash -c '/usr/bin/ip addr add 192.168.1.11/24 dev mac0'
ExecStartPre=/usr/bin/bash -c '/usr/bin/ip link set mac0 up'
ExecStartPre=-/usr/bin/bash -c '/usr/bin/ip route add 192.168.1.0/24 dev mac0'
ExecStartPre=/usr/bin/bash -c '/usr/bin/ip route add default via 192.168.1.1'
ExecStartPre=/usr/bin/bash -c '/usr/bin/ip route add 198.18.0.0/16 via 192.168.1.1' # for fake ip (optional)
ExecStartPre=/usr/bin/bash -c 'ip rule add to 192.168.1.0/24 priority 2500 lookup main'
ExecStart=/usr/bin/bash -c '/usr/bin/echo done'
Restart=on-failure

[Install]
WantedBy=multi-user.target

Add macvlan net
https://blog.justforlxz.com/2024/04/15/Add-macvlan-net/
作者
小竹
发布于
2024年4月15日
许可协议