Last active
October 17, 2016 15:27
-
-
Save theredcat/604994e612df7e77f323bb502809bc49 to your computer and use it in GitHub Desktop.
Add veth to LXC container
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
function lxcaddveth() { | |
local pid=$(lxc-info -n ${1} -p | awk '{print $2}') | |
mkdir -p /var/run/netns | |
ln -sf /proc/$pid/ns/net "/var/run/netns/${1}" | |
ip link add name veth${2} type veth peer name veth${2}_c | |
ip link set dev veth${2}_c netns ${1} name ${3} | |
lxc-attach -n ${1} /sbin/ifconfig ${3} up | |
/sbin/ifconfig veth${2} up | |
brctl addif ${4} veth${2} | |
lxc-attach -n ${1} dhclient ${3} | |
rm -f "/var/run/netns/${1}" | |
} | |
example: | |
- "my_container" is the target container for the new veth | |
- "QwERTY" is a random string for the veth name on the host (do NOT use "QWERTY") | |
- eth1 is the name of the veth in the container | |
- br1 is the bridge to add the veth to on the host | |
lxcaddveth my_container QWERTY eth1 br1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment