zoukankan      html  css  js  c++  java
  • Linux network namespace

    create & delete & list & exec network namespace

    # ip netns add test1
    # ip netns list test1
    # ip netns delete test1
    
    # ip netns exec test1 ip a
    1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    
    # ip netns exec test1 ip link
    1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    
    # ip netns exec test1 ip link set dev lo up
    # ip netns exec test1 ip link 
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    
    # mode由DOWN变为UNKNOWN
    

    add interface to a network namespace

    # ip link add veth-a type veth peer name veth-b
    # ip link
    
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
        link/ether 52:54:00:25:66:c8 brd ff:ff:ff:ff:ff:ff
    3: veth-b@veth-a: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
        link/ether c2:32:fc:89:5c:61 brd ff:ff:ff:ff:ff:ff
    4: veth-a@veth-b: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
        link/ether da:8f:39:f7:09:1f brd ff:ff:ff:ff:ff:ff
    

    assign ip address to veth interface

    # ip addr add 192.168.8.155/24 dev veth-a
    # ip link set veth-a up
    # ip link
    
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
        link/ether 52:54:00:25:66:c8 brd ff:ff:ff:ff:ff:ff
    3: veth-b@veth-a: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
        link/ether c2:32:fc:89:5c:61 brd ff:ff:ff:ff:ff:ff
    4: veth-a@veth-b: <NO-CARRIER,BROADCAST,MULTICAST,UP,M-DOWN> mtu 1500 qdisc noqueue state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
        link/ether da:8f:39:f7:09:1f brd ff:ff:ff:ff:ff:ff
    
    # mode LOWERLAYERDOWN
    
    # ip addr add 192.168.8.156/24 dev veth-b
    # ip link set veth-b up
    # ip link
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
        link/ether 52:54:00:25:66:c8 brd ff:ff:ff:ff:ff:ff
    3: veth-b@veth-a: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
        link/ether c2:32:fc:89:5c:61 brd ff:ff:ff:ff:ff:ff
    4: veth-a@veth-b: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
        link/ether da:8f:39:f7:09:1f brd ff:ff:ff:ff:ff:ff
    
    # mode UP
    
  • 相关阅读:
    Python语法解析器PLY——lex and yacc in Python
    spider-lang :爬虫语言,专为网络爬虫设计
    使用ANTLR做一个简单的Python SQL语法解析器
    使用Antlr实现简单的DSL
    Wrights Notes
    20个人团建能干些什么?
    zz
    贾跃亭反思乐视节奏过快_公司频道_财新网
    西湖人才网 职称考评
    安能物流
  • 原文地址:https://www.cnblogs.com/liujitao79/p/15192682.html
Copyright © 2011-2022 走看看