Linux Network Namespace (netns) 详解

Network Namespace (以下简称netns)是Linux内核提供的一项实现网络隔离的功能,它能隔离多个不同的网络空间,并且各自拥有独立的网络协议栈,这其中便包括了网络接口(网卡),路由表,iptables规则等。例如大名鼎鼎的docker便是基于netns实现的网络隔离,今天我们就来手动实验一下netns的隔离特性。 使用方式 使用ip netns help查看使用帮助 Usage: ip netns list ip netns add NAME ip netns set NAME NETNSID ip [-all] netns delete [NAME] ip netns identify [PID] ip netns pids NAME ip [-all] netns exec [NAME] cmd ... ip netns monitor ip netns list-id 开始实验 我们将要构建如下图的网络 首先我们添加两个tap设备并配置上IP信息,然后添加两个netns,最后将tap设备移动到netns中 # 添加并启动虚拟网卡tap设备 ip tuntap add dev tap0 mode tap ip tuntap add dev tap1 mode tap ip link set tap0 up ip link set tap1 up # 配置IP ip addr add 10....

November 8, 2020 · 3 分钟 · dushixiang