Created
June 18, 2015 17:07
-
-
Save trapier/4ffcb1c03fa2d1157274 to your computer and use it in GitHub Desktop.
follow an interface with an ip address into its own namespace
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 | |
ns_name=$1 | |
iface=$2 | |
addr=$3 | |
ip netns add ${ns_name} | |
ip a flush ${iface} | |
ip l s ${iface} down | |
ip l s ${iface} netns ${ns_name} | |
ip netns exec ${ns_name} /bin/bash -c "ip addr add ${addr} dev ${iface}" | |
ip netns exec ${ns_name} /bin/bash -c "ip l s ${iface} up" | |
cp ~/.bashrc /tmp/${ns_name}.bashrc | |
echo export PS1='('${ns_name}')$PS1' >> /tmp/${ns_name}.bashrc | |
ip netns exec ${ns_name} /bin/bash --init-file /tmp/${ns_name}.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment