Skip to content

Instantly share code, notes, and snippets.

@eslutsky
Last active July 27, 2020 09:41
Show Gist options
  • Save eslutsky/430981a0298e34fc45f5a8f9b502754e to your computer and use it in GitHub Desktop.
Save eslutsky/430981a0298e34fc45f5a8f9b502754e to your computer and use it in GitHub Desktop.
#!/bin/bash
parentNIC=eth0
newNIC=macvlan0
macAddress=00:1a:4a:23:17:2d
# add new macvlan interface
ip link add dev $newNIC link $parentNIC type macvlan
# change mac address for the NIC
ip link set dev $newNIC address $macAddress
#save routes
ip route save >/tmp/routes
# run dhcp client for the new interface
dhclient -v -pf /tmp/aa.pid $newNIC
sleep 1
# show the address received for the NIC
ip addr show $newNIC
# cleanup and restore routes
pkill -F /tmp/aa.pid
ip link del dev $newNIC
ip route restore </tmp/routes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment