Skip to content

Instantly share code, notes, and snippets.

@trapier
Created June 18, 2015 17:07
Show Gist options
  • Save trapier/4ffcb1c03fa2d1157274 to your computer and use it in GitHub Desktop.
Save trapier/4ffcb1c03fa2d1157274 to your computer and use it in GitHub Desktop.
follow an interface with an ip address into its own namespace
#!/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