当前位置: 首页 > news >正文

网络命令配置

随笔记录

目录

1. 背景介绍

2. 配置网络命令空间

3 验证

3.1 未网络命令空间外网卡配置IP

3.2 验证配置

3.2.1  在网络命令空间外接口启动iperf3

3.2.2 网络命令空间内启动iperf3 client


1. 背景介绍

2. 配置网络命令空间

1. 配置前[root@localhost SDK-V1.10.1.7]# ip netns exec netABC bash
Cannot open network namespace "netABC": No such file or directory
[root@localhost SDK-V1.10.1.7]# 2. 创建网络命令空间  
# ip netns add <网络命令空间名>[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ip netns add netABC  
[root@localhost SDK-V1.10.1.7]# 3. 查看存在的网络命令空间
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ip netns list    
netABC
[root@localhost SDK-V1.10.1.7]# 4. 查询网络接口,并将接口添加到网络命令空间
# 查询网阔接口
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255inet6 fe80::5a11:22ff:fe9e:2888  prefixlen 64  scopeid 0x20<link>ether 58:11:22:9e:28:88  txqueuelen 1000  (Ethernet)RX packets 98650  bytes 112990563 (107.7 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 49070  bytes 4039655 (3.8 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1000  (Local Loopback)RX packets 58  bytes 4946 (4.8 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 58  bytes 4946 (4.8 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500ether 32:74:4f:81:e0:e2  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 847  dropped 0  overruns 0  frame 847TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500ether f6:38:ce:dd:9f:ed  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:56:07:08  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# 5. 将指定网络接口添加到网络命令空间
# ip link set <网络接口> netns netABC[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ip link set swift1f1 netns netABC
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ip netns exec netABC bash
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig swift1f1 up
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig
swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::f438:ceff:fedd:9fed  prefixlen 64  scopeid 0x20<link>ether f6:38:ce:dd:9f:ed  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 6  bytes 516 (516.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.7]# 
root@localhost SDK-V1.10.1.7]# ip netns exec netABC bash
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig swift1f1 up
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig               # 分配IP 前
swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::f438:ceff:fedd:9fed  prefixlen 64  scopeid 0x20<link>ether f6:38:ce:dd:9f:ed  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 6  bytes 516 (516.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.7]# [root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ip route     # 配置Route 前
[root@localhost SDK-V1.10.1.7]# 6. 为网络命令空间中接口指定IP/Route
# 指定IP
# ifconfig <接口名> <IP/掩码>root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig swift1f1 11.1.1.77/24
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig
swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 11.1.1.77  netmask 255.255.255.0  broadcast 11.1.1.255inet6 fe80::f438:ceff:fedd:9fed  prefixlen 64  scopeid 0x20<link>ether f6:38:ce:dd:9f:ed  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 15  bytes 1146 (1.1 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ip route      # 添加Route
11.1.1.0/24 dev swift1f1 proto kernel scope link src 11.1.1.77 
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# 7. 退出网络命令空间
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# exit
logoutConnection closed.Disconnected from remote host(10.1.22.73-NDPP) at 10:47:57.Type `help' to learn how to use Xshell prompt.
[C:\~]$ 8. 删除网络命令空间
# ip netns delete <网络命令空间名称> 
[root@localhost ~]# 
[root@localhost ~]# ip netns delete netABC  //删除网络命令空间
[root@localhost ~]# 
[root@localhost ~]# ip netns list
[root@localhost ~]# 

注意:不进入网络命令空间也可以进行以上配置。

# 不进入网络命令空间,进行以上配置,只需要在执行命令前添加
# ip netns exec <网络命令空间名称> <需要执行命令>比如查询 ip route
# ip netns exec netABC ip route# 如 启动网络命令空间中接口
# ip netns exec netABC ifconfig swift1f1 up等等。[root@localhost SDK-V1.10.1.9]# ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255inet6 fe80::5a11:22ff:fe9e:2888  prefixlen 64  scopeid 0x20<link>ether 58:11:22:9e:28:88  txqueuelen 1000  (Ethernet)RX packets 1182797  bytes 1628346524 (1.5 GiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 592699  bytes 123898394 (118.1 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1000  (Local Loopback)RX packets 16755  bytes 381672557 (363.9 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 16755  bytes 381672557 (363.9 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500ether 88:63:c5:ee:e2:52  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500ether b2:c2:ae:e6:dc:47  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:56:07:08  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.9]# 
[root@localhost SDK-V1.10.1.9]# 
[root@localhost SDK-V1.10.1.9]# ip link set swift1f1 netns netABC
[root@localhost SDK-V1.10.1.9]# ip netns exec netABC ifconfig
[root@localhost SDK-V1.10.1.9]# 
[root@localhost SDK-V1.10.1.9]# ip netns exec netABC ifconfig swift1f1 up
[root@localhost SDK-V1.10.1.9]# 
[root@localhost SDK-V1.10.1.9]# ip netns exec netABC ifconfig
swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::b0c2:aeff:fee6:dc47  prefixlen 64  scopeid 0x20<link>ether b2:c2:ae:e6:dc:47  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 6  bytes 516 (516.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.9]# ip netns exec netABC ifconfig swift1f1 11.1.1.77/24
[root@localhost SDK-V1.10.1.9]# ip netns exec netABC ifconfig
swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 11.1.1.77  netmask 255.255.255.0  broadcast 11.1.1.255inet6 fe80::b0c2:aeff:fee6:dc47  prefixlen 64  scopeid 0x20<link>ether b2:c2:ae:e6:dc:47  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 9  bytes 726 (726.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.9]# 
[root@localhost SDK-V1.10.1.9]# ip netns exec netABC ip route
11.1.1.0/24 dev swift1f1 proto kernel scope link src 11.1.1.77 
[root@localhost SDK-V1.10.1.9]# 
[root@localhost SDK-V1.10.1.9]# 
[root@localhost SDK-V1.10.1.9]# ip route
default via 10.1.22.1 dev enp5s0 proto static metric 100 
10.1.22.0/24 dev enp5s0 proto kernel scope link src 10.1.22.73 metric 100 
192.168.2.0/24 via 10.1.22.1 dev enp5s0 proto static metric 100 
192.168.4.0/22 via 10.1.22.1 dev enp5s0 proto static metric 100 
192.168.30.0/24 via 10.1.22.1 dev enp5s0 proto static metric 100 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 
[root@localhost SDK-V1.10.1.9]# 

3 验证

3.1 未网络命令空间外网卡配置IP

# 注意:
# 因个人需求需要 网络命令空间内的网卡 swift1f1 与 网口命令空间外的网卡 swift1f0 互通,
所以需要配置同一网段。即:
swift1f0: 11.1.1.73/24
swift1f1: 11.1.1.77/24# 配置IP 前
[root@localhost SDK-V1.10.1.7]# ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255inet6 fe80::5a11:22ff:fe9e:2888  prefixlen 64  scopeid 0x20<link>ether 58:11:22:9e:28:88  txqueuelen 1000  (Ethernet)RX packets 100905  bytes 113208973 (107.9 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 50245  bytes 4158774 (3.9 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1000  (Local Loopback)RX packets 94  bytes 10310 (10.0 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 94  bytes 10310 (10.0 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500ether 32:74:4f:81:e0:e2  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 847  dropped 0  overruns 0  frame 847TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:56:07:08  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# # 配置IP
# ip addr add <IP>/<掩码> dev <网卡名>[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ip addr add 11.1.1.73/24 dev swift1f0
[root@localhost SDK-V1.10.1.7]# 
[root@localhost SDK-V1.10.1.7]# ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255inet6 fe80::5a11:22ff:fe9e:2888  prefixlen 64  scopeid 0x20<link>ether 58:11:22:9e:28:88  txqueuelen 1000  (Ethernet)RX packets 101034  bytes 113221673 (107.9 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 50314  bytes 4166866 (3.9 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1000  (Local Loopback)RX packets 106  bytes 11330 (11.0 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 106  bytes 11330 (11.0 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 11.1.1.73  netmask 255.255.255.0  broadcast 0.0.0.0ether 32:74:4f:81:e0:e2  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 847  dropped 0  overruns 0  frame 847TX packets 8  bytes 858 (858.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:56:07:08  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost SDK-V1.10.1.7]# 

3.2 验证配置

3.2.1  在网络命令空间外接口启动iperf3

#启动 iperf3 Server
#  iperf3 -B <网络命令空间外网卡IP> -p <Port> -i 1 -s[root@localhost SDK-V1.10.1.7]#
[root@localhost SDK-V1.10.1.7]# iperf3 -B 11.1.1.73 -p 54321 -i 1 -s
-----------------------------------------------------------
Server listening on 54321
-----------------------------------------------------------

3.2.2 网络命令空间内启动iperf3 client

# 网络命令空间内 启动 ipfer3 client# 1. 进入 网络命令空间#  ip netns exec netABC bash# 2. 启动iperf3 client# iperf3 -c <iperf3 Server IP> -p <Server Port> -t <发包时间>   # 发包时间单位 S[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# ip netns exec netABC bash
[root@localhost ~]# 
[root@localhost ~]# ip netns list
netABC
[root@localhost ~]# 
[root@localhost ~]# ip route list
11.1.1.0/24 dev swift1f1 proto kernel scope link src 11.1.1.77 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# iperf3 -c 11.1.1.73 -p 54321 -t 10

到此已完成网络命令空间配置 


http://www.mrgr.cn/news/79054.html

相关文章:

  • 推荐一款JTools的jtools-mybatis-log插件
  • 使用GDI对象绘制UI时需要注意的若干细节问题总结
  • string类函数的手动实现
  • getchar()
  • STM32F103 HSE时钟倍频以及设置频率函数(新手向,本人也是新手)
  • STM32 ADC --- 多通道序列采样
  • AD学习笔记·空白工程的创建
  • React 第九节 组件之间通讯之props 和回调函数
  • 重生之我在异世界学编程之C语言:深入指针篇(上)
  • 组合问题变式——选数(dfs)
  • 嵌入式硬件面试题【经验】总结----会不断添加更新
  • IDL学习笔记(二)IDL处理卫星数据
  • 使用playwright自动化测试时,npx playwright test --ui打开图形化界面时报错
  • L15.【LeetCode笔记】相同的树
  • 同时将scss全局变量注入、Tailwind样式使用、自己插件配置到vite
  • 汽车IVI中控OS Linux driver开发实操(二十七):常用Linux指令
  • 记录vite关于tailwindcss4.0-bate4出现margin[m-*]、padding[p-*]无法生效的问题。
  • 神经网络中的优化方法(一)
  • Android 应用单元测试涉及 Telephony 环境初始化问题
  • 浏览器的事件循环机制
  • 深入解析 Dubbo 中的常见问题及优化方案: 数据量限制与配置错误20241203
  • 嵌入式系统应用-LVGL的应用-平衡球游戏 part1
  • 三维地形图计算软件(四)-用PYQT5+vtk画任意多面体示例
  • 澎峰科技助力中国移动 重磅发布智算“芯合”算力原生基础软件栈2.0
  • 网络安全-夜神模拟器如何通过虚拟机的Burp Suite代理应用程序接口
  • 3GPP R18 LTM(L1/L2 Triggered Mobility)是什么鬼?(三) RACH-less LTM cell switch