Skip to content

Instantly share code, notes, and snippets.

@niedbalski
Last active June 22, 2021 03:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save niedbalski/ea84a2dd7a7a5b50cda0 to your computer and use it in GitHub Desktop.
Save niedbalski/ea84a2dd7a7a5b50cda0 to your computer and use it in GitHub Desktop.
netns-lxc
$ source netns-lxc.sh && sudo veth_interface_for_lxc container_name
veth132
function veth_interface_for_lxc() {
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}"
local index=$(ip netns exec "${1}" ip link show eth0 | head -n1 | sed s/:.*//)
let index=index+1
ip link show | grep "^${index}:" | sed "s/${index}: \(.*\):.*/\1/"
rm -f "/var/run/netns/${1}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment