Last active
July 27, 2020 09:41
-
-
Save eslutsky/430981a0298e34fc45f5a8f9b502754e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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