• 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
    
  • 相关阅读:
    SQL0668N Operation not allowed for reason code "3" on table "TEST". SQLSTATE=57016
    为何存在requests库,pycharm依然报错解决方法 --转载
    vmware12启动centos6.8报错ACPI:memory_hp:Memory online failed
    deepin升级之后打不开控制中心
    ubuntu中接一个摄像头会出现两个/dev/video
    VMware16中Ubuntu不显示共享文件夹的解决办法
    opencv获取当前帧数据问题
    libusb函数
    设置ubuntu、deppin(等linux系统)和window双系统启动引导顺序
    window和ubuntu双系统删除"ubuntu"
  • 原文地址:https://www.cnblogs.com/liujitao79/p/15192682.html
Copyright © 2020-2023  润新知