`
haoningabc
  • 浏览: 1475345 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

neutron基础二(namespace)

阅读更多
试验:
1.建立个namespace 名字为test
2.简历个veth peer,一个放入test里面
3.使test里面的网络能ping到外面的veth peer
4.设置ip route使test里面的网络能ping到外面的ip


创建一个namespace
[root@centos7 ~]# ip netns add test
[root@centos7 ~]# ip netns
test
[root@centos7 ~]# ip netns exec test ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00


[root@centos7 ~]# ip netns exec test bash
[root@centos7 ~]# ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
[root@centos7 ~]# ip netns identify $$
test
[root@centos7 ~]# exit
exit


在namespace里面使用普通linux网络命令
[root@centos7 ~]# ip netns exec test ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
[root@centos7 ~]# ip netns exec test ip link set dev lo up
[root@centos7 ~]# ip netns exec test ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever


ping
[root@centos7 ~]# ip netns exec test ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.093 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.054 ms
^C
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.054/0.073/0.093/0.021 ms


增加一对veth peer ,把veth1扔进namespace
[root@centos7 ~]# ip link add type veth
[root@centos7 ~]# 
[root@centos7 ~]# 
[root@centos7 ~]# ip link set veth1 netns test
[root@centos7 ~]# ip netns exec test ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
6: veth1@if5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether ba:3f:cf:12:23:5d brd ff:ff:ff:ff:ff:ff link-netnsid 0

查看配对的veth peer
[root@centos7 ~]# ethtool -S veth0
NIC statistics:
     peer_ifindex: 6
[root@centos7 ~]# ip netns exec test ethtool -S veth1
NIC statistics:
     peer_ifindex: 5


把namespace中的veth启动起来
[root@centos7 ~]# ip netns exec test ip link set veth1 up
[root@centos7 ~]# ip netns exec test ip a 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
6: veth1@if5: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state LOWERLAYERDOWN qlen 1000
    link/ether ba:3f:cf:12:23:5d brd ff:ff:ff:ff:ff:ff link-netnsid 0


设置namespace里面的veth1的ip,和namespace外面的veth0的ip
[root@centos7 ~]# ip netns exec test ip addr add dev veth1 192.168.3.2/29
[root@centos7 ~]# ip route
default via 192.168.128.1 dev eth0 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 
192.168.128.0/20 dev eth0  proto kernel  scope link  src 192.168.139.55 
[root@centos7 ~]# ip addr add dev veth0 192.168.3.1/29
[root@centos7 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 50:50:18:aa:80:17 brd ff:ff:ff:ff:ff:ff
    inet 192.168.139.55/20 brd 192.168.143.255 scope global dynamic eth0
       valid_lft 2823sec preferred_lft 2823sec
    inet6 fe80::5250:18ff:feaa:8017/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 52:54:00:71:94:cc brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:71:94:cc brd ff:ff:ff:ff:ff:ff
5: veth0@if6: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether be:ab:06:b0:59:fa brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.3.1/29 scope global veth0
       valid_lft forever preferred_lft forever


查看路由表
[root@centos7 ~]# ip route
default via 192.168.128.1 dev eth0 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 
192.168.128.0/20 dev eth0  proto kernel  scope link  src 192.168.139.55 


启动外面的veth0
[root@centos7 ~]# ip link set veth0 up
[root@centos7 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 50:50:18:aa:80:17 brd ff:ff:ff:ff:ff:ff
    inet 192.168.139.55/20 brd 192.168.143.255 scope global dynamic eth0
       valid_lft 2788sec preferred_lft 2788sec
    inet6 fe80::5250:18ff:feaa:8017/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 52:54:00:71:94:cc brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:71:94:cc brd ff:ff:ff:ff:ff:ff
5: veth0@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether be:ab:06:b0:59:fa brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.3.1/29 scope global veth0
       valid_lft forever preferred_lft forever
    inet6 fe80::bcab:6ff:feb0:59fa/64 scope link 
       valid_lft forever preferred_lft forever

再次查看路由表
[root@centos7 ~]# ip route
default via 192.168.128.1 dev eth0 
192.168.3.0/29 dev veth0  proto kernel  scope link  src 192.168.3.1 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 
192.168.128.0/20 dev eth0  proto kernel  scope link  src 192.168.139.55 
[root@centos7 ~]# ip netns exec test ip route
192.168.3.0/29 dev veth1  proto kernel  scope link  src 192.168.3.2 
[root@centos7 ~]# ping 192.168.3.2
PING 192.168.3.2 (192.168.3.2) 56(84) bytes of data.
64 bytes from 192.168.3.2: icmp_seq=1 ttl=64 time=0.091 ms
64 bytes from 192.168.3.2: icmp_seq=2 ttl=64 time=0.076 ms
^C
--- 192.168.3.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.076/0.083/0.091/0.011 ms


设置路由之后就通了
[root@centos7 ~]# 
[root@centos7 ~]# 
[root@centos7 ~]# ping 192.168.3.2
PING 192.168.3.2 (192.168.3.2) 56(84) bytes of data.
64 bytes from 192.168.3.2: icmp_seq=1 ttl=64 time=0.117 ms
64 bytes from 192.168.3.2: icmp_seq=2 ttl=64 time=0.073 ms
64 bytes from 192.168.3.2: icmp_seq=3 ttl=64 time=0.045 ms
64 bytes from 192.168.3.2: icmp_seq=4 ttl=64 time=0.050 ms
64 bytes from 192.168.3.2: icmp_seq=5 ttl=64 time=0.057 ms
^C
--- 192.168.3.2 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.045/0.068/0.117/0.027 ms
[root@centos7 ~]# 


★★换另一个ssh终端

[root@centos7 ~]# ip netns exec test tcpdump -i veth1 -l
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on veth1, link-type EN10MB (Ethernet), capture size 65535 bytes
08:01:59.180834 IP 192.168.3.1 > centos7: ICMP echo request, id 4142, seq 1, length 64
08:01:59.180899 IP centos7 > 192.168.3.1: ICMP echo reply, id 4142, seq 1, length 64
08:02:00.181087 IP 192.168.3.1 > centos7: ICMP echo request, id 4142, seq 2, length 64
^C
10 packets captured
10 packets received by filter
0 packets dropped by kernel


[root@centos7 ~]# 
[root@centos7 ~]# 
[root@centos7 ~]# ip netns exec test ping 192.168.139.55
connect: Network is unreachable
[root@centos7 ~]# ip netns exec test ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
6: veth1@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether ba:3f:cf:12:23:5d brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.3.2/29 scope global veth1
       valid_lft forever preferred_lft forever
    inet6 fe80::b83f:cfff:fe12:235d/64 scope link 
       valid_lft forever preferred_lft forever



[root@centos7 ~]# ip netns exec test ip route
192.168.3.0/29 dev veth1  proto kernel  scope link  src 192.168.3.2 
[root@centos7 ~]# ip netns exec test ip route add default via 192.168.3.1
[root@centos7 ~]# 
[root@centos7 ~]# ip netns exec test ping 192.168.139.55
PING 192.168.139.55 (192.168.139.55) 56(84) bytes of data.
64 bytes from 192.168.139.55: icmp_seq=1 ttl=64 time=0.074 ms
^C
--- 192.168.139.55 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.074/0.074/0.074/0.000 ms
[root@centos7 ~]# 
分享到:
评论

相关推荐

    深入理解OpenStack之Neutron

    当neutron-server创建了路由器的数据结构后,neutron-l3-agent执行具体操作,例如调用命令行创建虚拟路由器、设置路由表、配置namespace和iptables规则。 - **neutron-dhcp-agent**:负责创建和管理虚拟DHCP服务器...

    OpenStack网络管理

    #### 二、OpenStack网络服务Neutron简介 Neutron作为OpenStack的核心项目之一,其主要职责是提供“网络即服务”的功能。通过Neutron,用户可以灵活地创建和管理虚拟网络,包括子网、路由器、负载均衡器等,实现了...

    《OpenStack云计算基础架构平台应用》试卷试题及答案.docx

    - **Neutron**: Neutron组件提供网络连接服务,支持二层VLAN隔离和三层路由功能。 - **Glance**: Glance为OpenStack提供了一个统一的接口来管理和存储虚拟机镜像,并且为Nova虚拟机提供镜像服务。 - **Swift与...

    云计算试题及答案解析.pdf

    24. Neutron是OpenStack的网络服务,它在控制节点上部署neutron server服务和插件,在网络节点上部署agent,而在计算节点上部署core plugin的agent以提供虚拟机的二层网络功能。存储节点并不直接部署service plugin...

    揭秘云计算习题库教学文案.docx

    【云计算基础概念】 1. 云计算的一大特征是“按需自助服务”,这意味着用户可以根据自己的需求自行选择并使用云服务,无需经过复杂的申请流程。 2. 无处不在的网络接入是云计算的重要特性,没有高效的网络,云计算...

    云计算试题及答案.docx

    Neutron是OpenStack的网络服务,部署在控制节点、网络节点和计算节点上,提供虚拟机的二层和三层网络功能。存储节点并不部署Neutron的service plugin agent,因为它主要负责存储服务,而不是网络服务。

    云计算试题及答案 (2).pdf

    Neutron是OpenStack中的网络服务,它在计算节点上部署的agent负责虚拟机的二层网络功能,而非存储节点。 对ESXi的管理可通过vSphere Client直接与ESXi主机交互,或者使用vCenter Server集中管理多个ESXi主机。这些...

    OpenStack企业级应用实践.docx

    OpenStack Neutron 参考实现的网络模型,通过在每个计算节点和网关节点上利用 namespace 来进行 3 层转发和 DVR,在大规模集群时,命名空间会占用大量系统资源,同时命名空间的 TCP / IP 协议栈转发性能比流表效率低...

    云计算试题及答案.pdf

    Neutron是OpenStack的网络服务,它在控制节点部署neutron server服务以及核心和附加插件。网络节点负责核心插件的agent和服务插件的agent,计算节点上部署核心插件的agent,存储节点并不部署service plugin的agent,...

    云计算试题及答案 (2).docx

    Neutron是OpenStack中的网络服务,它在控制节点、网络节点和计算节点上部署不同的服务组件,为虚拟机提供网络功能,题25对Neutron的部署结构进行了描述。 以上内容涵盖了云计算的基础知识、网络管理、存储技术、...

    苏宁 Docker 私有云实践 雷爱民.pdf

    首先,云计算平台架构是构建私有云的基础,涉及到各种组件和服务的集成。苏宁在私有云实践中使用了OpenStack平台,这是一个开源的云计算平台,它包括计算(Nova)、存储(Cinder)、镜像服务(Glance)、身份服务...

    《OpenStack云平台实战》2套期末考试卷AB卷带答案习题试卷模拟卷.docx

    - **Neutron**:负责提供网络连接服务,包括二层VLAN隔离和三层路由功能。 - **Glance**:提供虚拟机镜像服务。 - **Swift**:对象存储服务,而非块存储服务。 - **Keystone**:负责身份认证和授权管理。 #### 十四...

    《OpenStack云平台实战》课程测试试卷-1.docx

    - **Neutron**:提供网络连接服务,具备二层VLAN隔离功能,同时具备三层路由功能。 - **Glance**:为虚拟机镜像提供存储、查询和检索服务。 - **Swift**:提供对象存储服务,而非块存储服务。 - **Keystone**:为...

    Kubernetes架构权威指南.pdf

    - **Namespace**:对集群中的资源进行逻辑分组。 - **NetworkPolicy**:控制Pod之间的网络通信。 - **Node**:集群中的物理或虚拟机器。 - **PersistentVolume**:为Pod提供持久存储。 - **Pod**:Kubernetes的...

Global site tag (gtag.js) - Google Analytics