Last active
June 22, 2021 03:57
-
-
Save niedbalski/ea84a2dd7a7a5b50cda0 to your computer and use it in GitHub Desktop.
netns-lxc
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
$ source netns-lxc.sh && sudo veth_interface_for_lxc container_name | |
veth132 |
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 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