当前位置:网站首页>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
边栏推荐
- Wireshark分析抓包数据*.cap
- Afghan interim government security forces launched military operations against a hideout of the extremist organization "Islamic state"
- Classification of regression tests
- Kirk borne's selection of learning resources this week [click the title to download directly]
- Redis的发布与订阅
- Unlike the relatively short-lived industrial chain of consumer Internet, the industrial chain of industrial Internet is quite long
- Continuous test (CT) practical experience sharing
- NAT地址转换
- Debian10 compile and install MySQL
- PTA 1102 教超冠军卷
猜你喜欢

低代码助力企业数字化转型会让程序员失业?

将模型的记忆保存下来!Meta&UC Berkeley提出MeMViT,建模时间支持比现有模型长30倍,计算量仅增加4.5%...

Using stored procedures, timers, triggers to solve data analysis problems

debian10编译安装mysql

Redis集群与扩展

海量数据去重的hash,bitmap与布隆过滤器Bloom Filter

面试唯品会实习测试岗、抖音实习测试岗【真实投稿】

Learn to make dynamic line chart in 3 minutes!

socket编程之常用api介绍与socket、select、poll、epoll高并发服务器模型代码实现

A few simple steps to teach you how to see the K-line diagram
随机推荐
go语言的字符串类型、常量类型和容器类型
Classification of regression tests
Static routing configuration
财富证券证券怎么开户?通过链接办理股票开户安全吗
Simple configuration of single arm routing and layer 3 switching
How to open an account for wealth securities? Is it safe to open a stock account through the link
国内的软件测试会受到偏见吗
PTA 1101 B是A的多少倍
Unlike the relatively short-lived industrial chain of consumer Internet, the industrial chain of industrial Internet is quite long
DataSimba推出微信小程序,DataNuza接受全场景考验? | StartDT Hackathon
不能忽略的现货白银短线操作小技巧
Reject policy of thread pool
Do you really understand sticky bag and half bag? 3 minutes to understand it
Disk storage chain B-tree and b+ tree
Antisamy: a solution against XSS attack tutorial
线程池和单例模式以及文件操作
[demo] circular queue and conditional lock realize the communication between goroutines
Performance test process and plan
Nat address translation
debian10编译安装mysql