I have a script that should create a macvlan bridge in the host when it starts up. The host is an up-to-date Arch Linux. This is intended to allow host and guest to share the same network. I found instructions given at:https://www.furorteutonicus.eu/2013/08/04/enabling-host-guest-networking-with-kvm-macvlan-and-macvtap(Regarding the execution at startup, I also consulted How to write startup script for systemd and https://stackoverflow.com/questions/21830670/systemd-start-service-after-specific-service).The problem, however, is that the script is not effective at first try. It creates the macvlan device and the routing table, but doesn't make it possible for the host to ping the guest and vice-versa.But when executed a second time, it works - that is, despite an error message which reads create_macvlan_bridge.sh[4489]: RTNETLINK answers: File exists. Host can now ping guest as expected.It's supposed to work at first try, though, and I can't figure out why it's not. Can anyone help?[Update] I noticed the result of ip a shows a second inet entry for macvlan0@enp10s0 after the second execution:macvlan0@enp10s0:  mtu 1500 qdisc  noqueue state UP group default qlen 1000      link/ether da:a2:21:d1:95:24 brd ff:ff:ff:ff:ff:ff      inet 192.168.1.3/24 scope global macvlan0          valid_lft forever preferred_lft forever      inet 192.168.1.22/24 brd 192.168.1.255 scope global secondary macvlan0          valid_lft forever preferred_lft foreverNotice how this second ip address was provided by the dhcp from the router, and it has secondary attribute.The weird thing is that, after the second execution, the guest can ping the host at 192.168.1.3 and at the secondary address.Code is below.Script: /usr/local/bin/create_macvlan_bridge.sh#!/bin/sh# Evert Mouw, 2013# Modified by Marc Ranolfi, 2017-07-24# ------------# wait for network availability# ------------TESTHOST=kernel.orgwhile ! ping -q -c 1 $TESTHOST > /dev/nulldo    echo $0: Cannot ping $TESTHOST, waiting another 5 secs...    sleep 5done# ------------# network config# ------------HWLINK=enp10s0MACVLN=macvlan0IP=192.168.1.3/24NETWORK=192.168.1.0/24GATEWAY=192.168.1.1# ------------# setting up $MACVLN interface# ------------ip link add link $HWLINK $MACVLN type macvlan mode bridgeip address add $IP dev $MACVLNip link set dev $MACVLN up# ------------# routing table# ------------# empty routesip route flush dev $HWLINKip route flush dev $MACVLN# add routesip route add $NETWORK dev $MACVLN metric 0# add the default gatewayip route add default via $GATEWAYSystemd unit file: /etc/systemd/system/create_macvlan_bridge.service[Unit]Description=Create_macvlan_bridgeWants=network-online.targetAfter=network.target network-online.target dhcpcd.service[Service]Type=oneshotExecStart=/usr/local/bin/create_macvlan_bridge.sh[Install]WantedBy=multi-user.target
Script to create macvlan bridge on the host doesn't work unless it's run twice
networking;virtual machine;network interface;kvm;macvlan
The information detailed in the question's last update gave me an insight of where the problem lay.I had dhcpcd.service enabled for all interfaces. I tried disabling it and enabling only for enp10s0, and it worked.So:systemctl disable dhcpcdsystemctl enable dhcpcd@enp10s0and voila.