Following instructions given at (https://www.furorteutonicus.eu/2013/08/04/enabling-host-guest-networking-with-kvm-macvlan-and-macvtap/) in order to be able to reach my VM network from the host, I createdhave 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:
Thenhttps://www.furorteutonicus.eu/2013/08/04/enabling-host-guest-networking-with-kvm-macvlan-and-macvtap
(Regarding the execution at startup, I followed instructions fromalso consulted (How to write startup script for Systemd?) and (https://stackoverflow.com/questions/21830670/systemd-start-service-after-specific-service) to run the script on host startup.
The problem, however, is that the script doesn't do what it's supposed to, when it'sis not effective at first runtry. When I runIt 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 it workswhich reads "create_macvlan_bridge.sh[4489]: RTNETLINK answers: File exists".
This error message I'm referring to is: Host can now ping guest as expected.
create_macvlan_bridge.sh[4489]: RTNETLINK answers: File exists
I reinforce thatIt's supposed to work at first try, despite this messagethough, everything works as expected.
But I'd like it to work correctly the first timeand I can't figure out why it's not. Can anyone help?
The issue is present whether I'm invoking[Update] I noticed the script directly or viaresult of systemctl startip create_macvlan_bridgea.
[Edit] When shows a second create_macvlan_bridge.serviceinet is enabled, after booting, I get this outputentry for systemctl statusmacvlan0@enp10s0 after the second execution:
create_macvlan_bridge.service - Create_macvlan_bridge
Loadedmacvlan0@enp10s0: loaded (/etc/systemd/system/create_macvlan_bridge.service;<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
enabled; vendor preset: disabled)noqueue state UP group default qlen 1000
Active
link/ether da: inactive (dead) since <datetime> <timezone>; 15s ago
Processa2: 492 ExecStart=/usr/local/bin/create_macvlan_bridge.sh
(code=exited, status=0/SUCCESS)
Main PID21: 492 (code=exited, status=0/SUCCESS)
<datetime> <hostname> systemd[1]d1: Starting Create_macvlan_bridge...
<datetime> <hostname> create_macvlan_bridge.sh[492]95: ping24 brd ff:
kernel.orgff: Name or service not known
<datetime> <hostname> create_macvlan_bridge.sh[492]ff:
/usr/local/bin/create_macvlan_bridge.shff: Cannot ping kernel.org,
waiting another 5 secsff:ff
inet 192.168.1.3/24 scope global macvlan0
<datetime> <hostname> systemd[1]: Started Create_macvlan_bridge.
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 forever
Notice 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.