当前位置:网站首页>IP netns command (memo)
IP netns command (memo)
2022-07-07 18:55:00 【fananchong2】
Linux Network Namespace
Linux Network Namespace It is the foundation of containerization
ip netns Is based on Linux Network Namespace A utility for
Get familiar with it here ip netns Use , To understand how Linux Network virtualization under
establish 1 A virtual network
# Create a file called netns1 Of network namespace
sudo ip netns add netns1
# Use ip netns exec Order to enter network namespace
sudo ip netns exec netns1 ip link list
# Get into netns1 This network namespace , Set the device status to UP
sudo ip netns exec netns1 ip link set dev lo up
# Try ping netns1 This network namespace Of 127.0.0.1
sudo ip netns exec netns1 ping 127.0.0.1
# See what's in the system network namespace
ip netns list
# Delete network namespace
sudo ip netns delete netns1
2 Virtual network interworking
#!/bin/bash
# establish network namespace ns0 ns1
sudo ip netns add ns0
sudo ip netns add ns1
# Use veth pair establish 2 Virtual network card ; Add to respectively ns0 ns1 wetowrk namespace
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth0 netns ns0
sudo ip link set veth1 netns ns1
# binding ip
sudo ip netns exec ns0 ip link set dev lo up
sudo ip netns exec ns1 ip link set dev lo up
sudo ip netns exec ns0 ifconfig veth0 10.1.1.1/24 up
sudo ip netns exec ns1 ifconfig veth1 10.1.1.2/24 up
# Delete network namespace
sudo ip netns delete ns0
sudo ip netns delete ns1
Multiple virtual networks are interconnected
#!/bin/bash
### centos
## yum install -y bridge-utils
### ubuntu
## apt-get install -y bridge-utils
# Add the bridge br0
sudo brctl addbr br0
# Start the bridge br0
sudo ip link set br0 up
# establish network namespace ns0 ns1 ns2
sudo ip netns add ns0
sudo ip netns add ns1
sudo ip netns add ns2
# establish veth peer
sudo ip link add veth0-ns type veth peer name veth0-br
sudo ip link add veth1-ns type veth peer name veth1-br
sudo ip link add veth2-ns type veth peer name veth2-br
# take veth Move one end of to netns in
sudo ip link set veth0-ns netns ns0
sudo ip link set veth1-ns netns ns1
sudo ip link set veth2-ns netns ns2
# binding ip
sudo ip netns exec ns0 ip link set dev lo up
sudo ip netns exec ns1 ip link set dev lo up
sudo ip netns exec ns2 ip link set dev lo up
sudo ip netns exec ns0 ifconfig veth0-ns 10.1.1.1/24 up
sudo ip netns exec ns1 ifconfig veth1-ns 10.1.1.2/24 up
sudo ip netns exec ns2 ifconfig veth2-ns 10.1.1.3/24 up
# Set the default route , Can stay overnight host
sudo ip netns exec ns0 route add default gw 10.1.1.254 veth0-ns
sudo ip netns exec ns1 route add default gw 10.1.1.254 veth1-ns
sudo ip netns exec ns2 route add default gw 10.1.1.254 veth2-ns
# take veth The other end of is started and attached to the bridge
sudo ip link set veth0-br up
sudo ip link set veth1-br up
sudo ip link set veth2-br up
sudo brctl addif br0 veth0-br
sudo brctl addif br0 veth1-br
sudo brctl addif br0 veth2-br
# Set up the bridge IP
sudo ip addr add 10.1.1.254/24 dev br0
# Remove the bridge
sudo ifconfig veth0-br 0
sudo ifconfig veth1-br 0
sudo ifconfig veth2-br 0
sudo brctl delif br0 veth0-br
sudo brctl delif br0 veth1-br
sudo brctl delif br0 veth2-br
sudo ip link set br0 down
sudo brctl delbr br0
other
- I haven't got through the virtual network yet, how to access the external network
- The host restarts , The network settings of the above command will be reset , Reassurance experiment
边栏推荐
- 清华、剑桥、UIC联合推出首个中文事实核查数据集:基于证据、涵盖医疗社会等多个领域
- 嵌入式C语言程序调试和宏使用的技巧
- Interview vipshop internship testing post, Tiktok internship testing post [true submission]
- Usage of PHP interview questions foreach ($arr as $value) and foreach ($arr as $value)
- nest. Database for getting started with JS
- Charles+Postern的APP抓包
- Some key points in the analysis of spot Silver
- Comparison and selection of kubernetes Devops CD Tools
- Yearning-SQL审核平台
- Debian10 compile and install MySQL
猜你喜欢
More than 10000 units were offline within ten days of listing, and the strength of Auchan Z6 products was highly praised
[Tawang methodology] Tawang 3W consumption strategy - U & a research method
[PaddleSeg源码阅读] PaddleSeg Validation 中添加 Boundary IoU的计算(1)——val.py文件细节提示
Discuss | what preparations should be made before ar application is launched?
不能忽略的现货白银短线操作小技巧
debian10系统问题总结
单臂路由和三层交换的简单配置
C语言中匿名的最高境界
Will low code help enterprises' digital transformation make programmers unemployed?
嵌入式C语言程序调试和宏使用的技巧
随机推荐
[network attack and defense principle and technology] Chapter 4: network scanning technology
现货白银分析中的一些要点
What are the financial products in 2022? What are suitable for beginners?
体总:安全有序恢复线下体育赛事,力争做到国内赛事应办尽办
Comparison and selection of kubernetes Devops CD Tools
How to open an account for wealth securities? Is it safe to open a stock account through the link
Introduction of common API for socket programming and code implementation of socket, select, poll, epoll high concurrency server model
[software test] from the direct employment of the boss of the enterprise version, looking at the resume, there is a reason why you are not covered
线程池和单例模式以及文件操作
【剑指 Offer】59 - I. 滑动窗口的最大值
微信网页调试8.0.19换掉X5内核,改用xweb,所以x5调试方式已经不能用了,现在有了解决方案
Thread pool and singleton mode and file operation
云安全日报220707:思科Expressway系列和网真视频通信服务器发现远程攻击漏洞,需要尽快升级
Download, installation and development environment construction of "harmonyos" deveco
[Tawang methodology] Tawang 3W consumption strategy - U & a research method
AntiSamy:防 XSS 攻击的一种解决方案使用教程
如何选择合适的自动化测试工具?
[论文分享] Where’s Crypto?
你真的理解粘包与半包吗?3分钟搞懂它
[principle and technology of network attack and Defense] Chapter 6: Trojan horse