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

网络命令配置

随笔记录

目录

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 1500
        inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255
        inet6 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 0
        TX packets 49070  bytes 4039655 (3.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX packets 58  bytes 4946 (4.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 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 847
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        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 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 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 0
        TX 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 1500
        inet6 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 0
        TX 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 1500
        inet6 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 0
        TX 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 1500
        inet 11.1.1.77  netmask 255.255.255.0  broadcast 11.1.1.255
        inet6 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 0
        TX 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
logout

Connection 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 1500
        inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255
        inet6 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 0
        TX packets 592699  bytes 123898394 (118.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX packets 16755  bytes 381672557 (363.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 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 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

swift1f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        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 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 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 0
        TX 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 1500
        inet6 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 0
        TX 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 1500
        inet 11.1.1.77  netmask 255.255.255.0  broadcast 11.1.1.255
        inet6 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 0
        TX 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 1500
        inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255
        inet6 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 0
        TX packets 50245  bytes 4158774 (3.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX packets 94  bytes 10310 (10.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 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 847
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 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 0
        TX 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 1500
        inet 10.1.22.73  netmask 255.255.255.0  broadcast 10.1.22.255
        inet6 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 0
        TX packets 50314  bytes 4166866 (3.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::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 0
        TX packets 106  bytes 11330 (11.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

swift1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 11.1.1.73  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 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 847
        TX packets 8  bytes 858 (858.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 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 0
        TX 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.kler.cn/a/427810.html

相关文章:

  • C++ list
  • 使用大语言模型在表格化网络安全数据中进行高效异常检测
  • 【力扣】49.字母异位词分组
  • React 19 新特性探索:提升性能与开发者体验
  • socket实现HTTP请求,参考HttpURLConnection源码解析
  • Axure PR 9 旋转效果 设计交互
  • git强制覆盖本地更改
  • transformers实现一个检索机器人(一)
  • Velero 备份k8s
  • 项目五 李白个人生平(资源)
  • STM32基于HAL库的串口接收中断触发机制和适用场景
  • Linux絮絮叨(三) Ubuntu桌面版添加中文拼音输入法
  • Map和Set(下)
  • Swift 扩展
  • vm ubuntu黑屏
  • 【配置查询】.NET开源 ORM 框架 SqlSugar 系列
  • 光猫开DMZ教程
  • 为什么 JavaScript 中的箭头函数不生效?
  • 基于Springboot的校园交友网站设计与实现
  • c语言的思维导图
  • Web3与人工智能的跨界融合:数据隐私与去中心化的新机遇
  • 论文笔记:Asymptotic Midpoint Mixup for Margin Balancing and Moderate Broadening
  • SQL分类:DDL、DML、DCL
  • 如果MySQL中没有MVCC,会有什么影响?
  • rockit 学习、开发笔记(六)(VENC)
  • docker批量创建cloudstack虚拟主机脚本