Skip to content

Instantly share code, notes, and snippets.

@theredcat
Last active October 17, 2016 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theredcat/604994e612df7e77f323bb502809bc49 to your computer and use it in GitHub Desktop.
Save theredcat/604994e612df7e77f323bb502809bc49 to your computer and use it in GitHub Desktop.
Add veth to LXC container
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