Creating a virtual interface type macvlan
2
votes
1
answer
46
views
I have a Raspberry Pi OS Lite system installed. It has the following interfaces available
ip l
1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether bd:1e:96:ac:a3:40 brd ff:ff:ff:ff:ff:ff
3: wlan0: mtu 1500 qdisc noop state DOWN mode DORMANT group default qlen 1000
link/ether 29:a8:78:cd:57:6d brd ff:ff:ff:ff:ff:ff
I need to create a virtual interface type macvlan. I have a question about how to implement this correctly.
I have three options.
1. Add to the file /etc/network/interfaces
auto lan0
iface lan0 inet dhcp
pre-up ip link set eth0 up
pre-up ip link add link eth0 $IFACE type macvlan
post-down ip link delete $IFACE type macvlan
2. Create a file named lan0 in the /etc/network/interfaces.d directory with the following content
auto lan0
iface lan0 inet dhcp
pre-up ip link set eth0 up
pre-up ip link add link eth0 $IFACE type macvlan
post-down ip link delete $IFACE type macvlan
3. Create a file named lan0 in the /etc/network/if-up.d directory with the following content
#!/bin/sh
IPBIN=/usr/sbin/ip
test -x $IPBIN || exit 0
[ "$IFACE" != "eth0" ] && exit 0
$IPBIN link add link $IFACE lan0 type macvlan
$IPBIN link set dev lan0 up
However, in option 3, the IP address is not obtained automatically.
Asked by Raalgepis
(21 rep)
Jul 14, 2025, 08:33 AM
Last activity: Jul 16, 2025, 11:16 AM
Last activity: Jul 16, 2025, 11:16 AM