CentOS7 network namespaces
系统3年前 (2020-12-22)
通过创建2个网络命名空间和2个虚拟网卡,使2个虚拟网卡互通
+----------------------------------------------------------------+ | | | +------------------------------------------------+ | | | Newwork Protocol Stack | | | +------------------------------------------------+ | | ↑ ↑ ↑ | |..............|...............|...............|.................| | ↓ ↓ ↓ | | +----------+ +-----------+ +-----------+ | | | eth0 | | veth0 | | veth1 | | | +----------+ +-----------+ +-----------+ | |192.168.1.2 ↑ ↑ ↑ | | | +---------------+ | | | 10.0.0.100 10.0.0.200 | +--------------|-------------------------------------------------+ ↓ Physical Network
创建2个虚拟网络空间
ip netns add ns0 ip netns add ns1 ll /var/run/netns
创建2个虚拟网卡
ip link add veth0 type veth peer name veth1 ip link set veth0 netns ns0 ip link set veth1 netns ns1 ip netns exec ns0 ifconfig -a
添加ip地址
ip netns exec ns0 ifconfig veth0 10.0.0.100/24 up ip netns exec ns1 ifconfig veth1 10.0.0.200/24 up ip netns exec ns1 ifconfig -a
测试
ip netns exec ns0 ping 10.0.0.200 -c 10
本站所有文章均可随意转载,转载时请保留原文链接及作者。