Linux 虚拟网络设备

本文详细介绍了Linux中的虚拟网络设备,包括tun/tap设备的工作原理、使用方法和示例,veth设备的特性、配置和应用,以及bridge(虚拟交换机)的创建、管理及其在网络中的作用。通过这些设备,可以在Linux系统中模拟网络层和链路层设备,创建虚拟网络环境,用于软件定义网络(SDN)和网络功能虚拟化(NFV)等场景。
摘要由CSDN通过智能技术生成

一、tun/tap(虚拟网卡)

TUN/TAP设备浅析(一) – 原理浅析 - 简书 (jianshu.com)

(3条消息) Linux-虚拟网络设备-tun/tap_sld880311的专栏-CSDN博客_linux tap

理解Linux虚拟网卡设备tun/tap的一切 | 骏马金龙 (junmajinlong.com)

Linux-虚拟网络设备-tun/tap_sld880311的专栏-CSDN博客_linux tap

1、特点

TUN 和 TAP 设备是 Linux 内核虚拟网络设备,纯软件实现。

TUN(TUNnel)设备模拟网络层设备,处理三层报文如 IP 报文。TAP 设备模拟链路层设备,处理二层报文,比如以太网帧。

2、使用方法

Linux 提供了一些命令行程序方便我们来创建持久化的tun/tap设备,但是如果没有应用程序打开对应的文件描述符,tun/tap的状态一直会是DOWN,还好的是这并不会影响我们把它当作普通网卡去使用。

onlylove@ubuntu:~$ ip tuntap help
Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ]
	[ mode { tun | tap } ] [ user USER ] [ group GROUP ]
	[ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ] [ name NAME ]

Where:	USER  := { STRING | NUMBER }
	GROUP := { STRING | NUMBER }
onlylove@ubuntu:~$
# 创建 tap 
ip tuntap add dev tap0 mode tap 
# 创建 tun
ip tuntap add dev tun0 mode tun 

# 删除 tap
ip tuntap del dev tap0 mode tap
# 删除 tun
ip tuntap del dev tun0 mode tun 

3、示例

1、tap(二层网络设备)

# 添加 tap 网卡
sudo ip tuntap add dev tap0 mode tap

# 启动 tap 网卡
sudo ip link set dev tap0 up

# 给 tap 设置 ip 地址
sudo ip address add dev tap0 192.168.1.128/24

# 显示所有的路由信息
ip route show

# 删除网卡
sudo ip tuntap del dev tap0 mode tap
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 13906  bytes 7451463 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5427  bytes 729793 (729.7 KB)
        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 2665  bytes 155516 (155.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2665  bytes 155516 (155.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ clear
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 13988  bytes 7457366 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5470  bytes 734415 (734.4 KB)
        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 2665  bytes 155516 (155.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2665  bytes 155516 (155.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ clear
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 14031  bytes 7460576 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5498  bytes 738063 (738.0 KB)
        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 2665  bytes 155516 (155.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2665  bytes 155516 (155.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ ip route show
default via 192.168.6.2 dev ens33 proto static metric 100 
169.254.0.0/16 dev ens33 scope link metric 1000 
192.168.6.0/24 dev ens33 proto kernel scope link src 192.168.6.129 metric 100 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip tuntap add dev tap0 mode tap
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 14098  bytes 7465506 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5535  bytes 742715 (742.7 KB)
        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 2665  bytes 155516 (155.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2665  bytes 155516 (155.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 14125  bytes 7467546 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5555  bytes 745387 (745.3 KB)
        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 2665  bytes 155516 (155.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2665  bytes 155516 (155.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 52:19:9d:b8:18:d7  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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip link set dev tap0 up
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 14165  bytes 7470368 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5573  bytes 748423 (748.4 KB)
        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 2665  bytes 155516 (155.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2665  bytes 155516 (155.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 52:19:9d:b8:18:d7  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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip address add dev tap0 192.168.1.128/24
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 14263  bytes 7478478 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5648  bytes 756811 (756.8 KB)
        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 2675  bytes 156336 (156.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2675  bytes 156336 (156.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.1.128  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 52:19:9d:b8:18:d7  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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ip route show
default via 192.168.6.2 dev ens33 proto static metric 100 
169.254.0.0/16 dev ens33 scope link metric 1000 
192.168.1.0/24 dev tap0 proto kernel scope link src 192.168.1.128 linkdown 
192.168.6.0/24 dev ens33 proto kernel scope link src 192.168.6.129 metric 100 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip tuntap del dev tap0 mode tap
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 14317  bytes 7482917 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5684  bytes 761877 (761.8 KB)
        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 2693  bytes 158036 (158.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2693  bytes 158036 (158.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 

2、tun(三层网络设备)

# 添加 tun 网卡
sudo ip tuntap add dev tun0 mode tun

# 启动 tun 网卡
sudo ip link set dev tun0 up

# 给 tun 设置 ip 地址
sudo ip address add dev tun0 192.168.1.128/24

# 显示所有的路由信息
ip route show

# 删除网卡
sudo ip tuntap del dev tun0 mode tun
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 14987  bytes 7532982 (7.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6118  bytes 813370 (813.3 KB)
        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 2735  bytes 162084 (162.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2735  bytes 162084 (162.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ip route show
default via 192.168.6.2 dev ens33 proto static metric 100 
169.254.0.0/16 dev ens33 scope link metric 1000 
192.168.6.0/24 dev ens33 proto kernel scope link src 192.168.6.129 metric 100 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip tuntap add dev tun0 mode tun
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 15099  bytes 7541904 (7.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6192  bytes 821668 (821.6 KB)
        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 2737  bytes 162256 (162.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2737  bytes 162256 (162.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 15127  bytes 7543974 (7.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6209  bytes 824160 (824.1 KB)
        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 2737  bytes 162256 (162.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2737  bytes 162256 (162.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun0: flags=4240<POINTOPOINT,NOARP,MULTICAST>  mtu 1500
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip link set dev tun0 up
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 15160  bytes 7546406 (7.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6234  bytes 827716 (827.7 KB)
        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 2737  bytes 162256 (162.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2737  bytes 162256 (162.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun0: flags=4241<UP,POINTOPOINT,NOARP,MULTICAST>  mtu 1500
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip address add dev tun0 192.168.1.128/24
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 15194  bytes 7549068 (7.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6255  bytes 831098 (831.0 KB)
        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 2745  bytes 162904 (162.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2745  bytes 162904 (162.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun0: flags=4241<UP,POINTOPOINT,NOARP,MULTICAST>  mtu 1500
        inet 192.168.1.128  netmask 255.255.255.0  destination 192.168.1.128
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ip route show
default via 192.168.6.2 dev ens33 proto static metric 100 
169.254.0.0/16 dev ens33 scope link metric 1000 
192.168.1.0/24 dev tun0 proto kernel scope link src 192.168.1.128 linkdown 
192.168.6.0/24 dev ens33 proto kernel scope link src 192.168.6.129 metric 100 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 15229  bytes 7551916 (7.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6278  bytes 834964 (834.9 KB)
        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 2751  bytes 163632 (163.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2751  bytes 163632 (163.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun0: flags=4241<UP,POINTOPOINT,NOARP,MULTICAST>  mtu 1500
        inet 192.168.1.128  netmask 255.255.255.0  destination 192.168.1.128
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip tuntap del dev tun0 mode tun
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 15269  bytes 7555038 (7.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6302  bytes 838604 (838.6 KB)
        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 2759  bytes 164280 (164.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2759  bytes 164280 (164.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 

二、veth

Linux虚拟网络设备之veth - SegmentFault 思否

Linux-虚拟网络设备-veth pair_sld880311的专栏-CSDN博客_linux veth

1、veth设备的特点

1、veth和其它的网络设备都一样,一端连接的是内核协议栈。

2、veth设备是成对出现的,另一端两个设备彼此相连。

3、一个设备收到协议栈的数据发送请求后,会将数据发送到另一个设备上去。

2、使用方法

onlylove@ubuntu:~$ ip link help
Usage: ip link add [link DEV] [ name ] NAME
		    [ txqueuelen PACKETS ]
		    [ address LLADDR ]
		    [ broadcast LLADDR ]
		    [ mtu MTU ] [index IDX ]
		    [ numtxqueues QUEUE_COUNT ]
		    [ numrxqueues QUEUE_COUNT ]
		    type TYPE [ ARGS ]

	ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]

	ip link set { DEVICE | dev DEVICE | group DEVGROUP }
			[ { up | down } ]
			[ type TYPE ARGS ]
		[ arp { on | off } ]
		[ dynamic { on | off } ]
		[ multicast { on | off } ]
		[ allmulticast { on | off } ]
		[ promisc { on | off } ]
		[ trailers { on | off } ]
		[ carrier { on | off } ]
		[ txqueuelen PACKETS ]
		[ name NEWNAME ]
		[ address LLADDR ]
		[ broadcast LLADDR ]
		[ mtu MTU ]
		[ netns { PID | NAME } ]
		[ link-netns NAME | link-netnsid ID ]
			[ alias NAME ]
			[ vf NUM [ mac LLADDR ]
				 [ vlan VLANID [ qos VLAN-QOS ] [ proto VLAN-PROTO ] ]
				 [ rate TXRATE ]
				 [ max_tx_rate TXRATE ]
				 [ min_tx_rate TXRATE ]
				 [ spoofchk { on | off} ]
				 [ query_rss { on | off} ]
				 [ state { auto | enable | disable} ] ]
				 [ trust { on | off} ] ]
				 [ node_guid { eui64 } ]
				 [ port_guid { eui64 } ]
			[ { xdp | xdpgeneric | xdpdrv | xdpoffload } { off |
				  object FILE [ section NAME ] [ verbose ] |
				  pinned FILE } ]
			[ master DEVICE ][ vrf NAME ]
			[ nomaster ]
			[ addrgenmode { eui64 | none | stable_secret | random } ]
			[ protodown { on | off } ]
			[ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]

	ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]

	ip link xstats type TYPE [ ARGS ]

	ip link afstats [ dev DEVICE ]
	ip link property add dev DEVICE [ altname NAME .. ]
	ip link property del dev DEVICE [ altname NAME .. ]

	ip link help [ TYPE ]

TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |
	   bridge | bond | team | ipoib | ip6tnl | ipip | sit | vxlan |
	   gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan |
	   vti | nlmon | team_slave | bond_slave | bridge_slave |
	   ipvlan | ipvtap | geneve | vrf | macsec | netdevsim | rmnet |
	   xfrm }
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ip link help veth
Usage: ip link <options> type veth [peer <options>]
To get <options> type 'ip link add help'
onlylove@ubuntu:~$

3、示例

# 添加 veth0 和 veth1
sudo ip link add veth0 type veth peer name veth1

# 为 veth0 配置 ip 地址
sudo ip addr add 192.168.2.11/24 dev veth0

# 为 veth1 配置 ip 地址
sudo ip addr add 192.168.2.5/24 dev veth1

# 启动 vteh0
sudo ip link set veth0 up

# 启动 vteh1
sudo ip link set veth1 up

# 删除 veth0 和 veth1
sudo ip link delete veth0 type veth peer name veth1
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 22931  bytes 15105317 (15.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8310  bytes 1051491 (1.0 MB)
        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 2961  bytes 181332 (181.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2961  bytes 181332 (181.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip link add veth0 type veth peer name veth1
[sudo] password for onlylove: 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 22984  bytes 15109265 (15.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8340  bytes 1055343 (1.0 MB)
        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 2961  bytes 181332 (181.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2961  bytes 181332 (181.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 23012  bytes 15111335 (15.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8357  bytes 1057873 (1.0 MB)
        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 2961  bytes 181332 (181.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2961  bytes 181332 (181.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 1a:c5:9b:ac:82:a2  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

veth1: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether fa:90:44:97:74:93  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

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip addr add 192.168.2.11/24 dev veth0
onlylove@ubuntu:~$ sudo ip addr add 192.168.2.5/24 dev veth1
onlylove@ubuntu:~$ sudo ip link set veth0 up
onlylove@ubuntu:~$ sudo ip link set veth1 up
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 23071  bytes 15116421 (15.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8402  bytes 1063497 (1.0 MB)
        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 3001  bytes 184572 (184.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3001  bytes 184572 (184.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.11  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::18c5:9bff:feac:82a2  prefixlen 64  scopeid 0x20<link>
        ether 1a:c5:9b:ac:82:a2  txqueuelen 1000  (Ethernet)
        RX packets 25  bytes 3011 (3.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11  bytes 1196 (1.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.5  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::f890:44ff:fe97:7493  prefixlen 64  scopeid 0x20<link>
        ether fa:90:44:97:74:93  txqueuelen 1000  (Ethernet)
        RX packets 11  bytes 1196 (1.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 25  bytes 3011 (3.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip link delete veth0 type veth peer name veth1
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 23106  bytes 15119275 (15.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8425  bytes 1067607 (1.0 MB)
        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 3017  bytes 185868 (185.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3017  bytes 185868 (185.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 

三、bridge(虚拟交换机)

Linux虚拟网络设备之bridge(桥) - SegmentFault 思否

Linux-虚拟网络设备-LinuxBridge_sld880311的专栏-CSDN博客_linux 虚拟交换机

1、特点

bridge是一个虚拟网络设备,所以具有网络设备的特征,可以配置IP、MAC地址等;其次,bridge是一个虚拟交换机,和物理交换机有类似的功能。

2、使用方法

onlylove@ubuntu:~$ ip link help
Usage: ip link add [link DEV] [ name ] NAME
		    [ txqueuelen PACKETS ]
		    [ address LLADDR ]
		    [ broadcast LLADDR ]
		    [ mtu MTU ] [index IDX ]
		    [ numtxqueues QUEUE_COUNT ]
		    [ numrxqueues QUEUE_COUNT ]
		    type TYPE [ ARGS ]

	ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]

	ip link set { DEVICE | dev DEVICE | group DEVGROUP }
			[ { up | down } ]
			[ type TYPE ARGS ]
		[ arp { on | off } ]
		[ dynamic { on | off } ]
		[ multicast { on | off } ]
		[ allmulticast { on | off } ]
		[ promisc { on | off } ]
		[ trailers { on | off } ]
		[ carrier { on | off } ]
		[ txqueuelen PACKETS ]
		[ name NEWNAME ]
		[ address LLADDR ]
		[ broadcast LLADDR ]
		[ mtu MTU ]
		[ netns { PID | NAME } ]
		[ link-netns NAME | link-netnsid ID ]
			[ alias NAME ]
			[ vf NUM [ mac LLADDR ]
				 [ vlan VLANID [ qos VLAN-QOS ] [ proto VLAN-PROTO ] ]
				 [ rate TXRATE ]
				 [ max_tx_rate TXRATE ]
				 [ min_tx_rate TXRATE ]
				 [ spoofchk { on | off} ]
				 [ query_rss { on | off} ]
				 [ state { auto | enable | disable} ] ]
				 [ trust { on | off} ] ]
				 [ node_guid { eui64 } ]
				 [ port_guid { eui64 } ]
			[ { xdp | xdpgeneric | xdpdrv | xdpoffload } { off |
				  object FILE [ section NAME ] [ verbose ] |
				  pinned FILE } ]
			[ master DEVICE ][ vrf NAME ]
			[ nomaster ]
			[ addrgenmode { eui64 | none | stable_secret | random } ]
			[ protodown { on | off } ]
			[ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]

	ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]

	ip link xstats type TYPE [ ARGS ]

	ip link afstats [ dev DEVICE ]
	ip link property add dev DEVICE [ altname NAME .. ]
	ip link property del dev DEVICE [ altname NAME .. ]

	ip link help [ TYPE ]

TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |
	   bridge | bond | team | ipoib | ip6tnl | ipip | sit | vxlan |
	   gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan |
	   vti | nlmon | team_slave | bond_slave | bridge_slave |
	   ipvlan | ipvtap | geneve | vrf | macsec | netdevsim | rmnet |
	   xfrm }
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ip link help bridge
Usage: ... bridge [ fdb_flush ]
		  [ forward_delay FORWARD_DELAY ]
		  [ hello_time HELLO_TIME ]
		  [ max_age MAX_AGE ]
		  [ ageing_time AGEING_TIME ]
		  [ stp_state STP_STATE ]
		  [ priority PRIORITY ]
		  [ group_fwd_mask MASK ]
		  [ group_address ADDRESS ]
		  [ vlan_filtering VLAN_FILTERING ]
		  [ vlan_protocol VLAN_PROTOCOL ]
		  [ vlan_default_pvid VLAN_DEFAULT_PVID ]
		  [ vlan_stats_enabled VLAN_STATS_ENABLED ]
		  [ vlan_stats_per_port VLAN_STATS_PER_PORT ]
		  [ mcast_snooping MULTICAST_SNOOPING ]
		  [ mcast_router MULTICAST_ROUTER ]
		  [ mcast_query_use_ifaddr MCAST_QUERY_USE_IFADDR ]
		  [ mcast_querier MULTICAST_QUERIER ]
		  [ mcast_hash_elasticity HASH_ELASTICITY ]
		  [ mcast_hash_max HASH_MAX ]
		  [ mcast_last_member_count LAST_MEMBER_COUNT ]
		  [ mcast_startup_query_count STARTUP_QUERY_COUNT ]
		  [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]
		  [ mcast_membership_interval MEMBERSHIP_INTERVAL ]
		  [ mcast_querier_interval QUERIER_INTERVAL ]
		  [ mcast_query_interval QUERY_INTERVAL ]
		  [ mcast_query_response_interval QUERY_RESPONSE_INTERVAL ]
		  [ mcast_startup_query_interval STARTUP_QUERY_INTERVAL ]
		  [ mcast_stats_enabled MCAST_STATS_ENABLED ]
		  [ mcast_igmp_version IGMP_VERSION ]
		  [ mcast_mld_version MLD_VERSION ]
		  [ nf_call_iptables NF_CALL_IPTABLES ]
		  [ nf_call_ip6tables NF_CALL_IP6TABLES ]
		  [ nf_call_arptables NF_CALL_ARPTABLES ]

Where: VLAN_PROTOCOL := { 802.1Q | 802.1ad }
onlylove@ubuntu:~$ 

3、示例

# 创建 bridge
sudo ip link add name br0 type bridge

# 启动 bridge
sudo ip link set br0 up

# 查看 bridge 上连接的设备
sudo bridge link

# 删除 bridge
sudo ip link delete name br0 type bridge

# 将 xxx 设备连接到 bridge 上
sudo ip link set dev xxx master br0
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 17478  bytes 7716741 (7.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7699  bytes 992070 (992.0 KB)
        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 2932  bytes 178733 (178.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2932  bytes 178733 (178.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip link add name br0 type bridge
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 17506  bytes 7718851 (7.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7719  bytes 994952 (994.9 KB)
        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 2932  bytes 178733 (178.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2932  bytes 178733 (178.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
br0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 4a:dd:f2:e6:a5:ba  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

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 17523  bytes 7720059 (7.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7729  bytes 996822 (996.8 KB)
        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 2932  bytes 178733 (178.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2932  bytes 178733 (178.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip link set br0 up
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::48dd:f2ff:fee6:a5ba  prefixlen 64  scopeid 0x20<link>
        ether 4a:dd:f2:e6:a5:ba  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1954 (1.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 17558  bytes 7722787 (7.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7754  bytes 1000380 (1.0 MB)
        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 2940  bytes 179381 (179.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2940  bytes 179381 (179.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo bridge link
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ sudo ip link delete name br0 type bridge
onlylove@ubuntu:~$ 
onlylove@ubuntu:~$ ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 17609  bytes 7726705 (7.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7787  bytes 1004970 (1.0 MB)
        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 2948  bytes 180029 (180.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2948  bytes 180029 (180.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ 

四、OpenvSwitch

Linux-虚拟网络设备-OpenvSwitch(持续更新)_sld880311的专栏-CSDN博客_linux openvswitch

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值