https://blog.csdn.net/zhaihaifei/article/details/38581247

https://www.cnblogs.com/weilu2/p/kvm_bridge_centos7.html

https://www.cnblogs.com/heyongboke/p/10337447.html

1 Linux添加虚拟网卡三种方法

方法1: ifconfig命令创建\删除虚拟网卡

ifconfig enp49s0f0:0 10.10.1.103 netmask 255.255.255.0 up

删除虚拟网卡:

ifconfig enp49s0f0:0 down

重启服务器或者网络后,虚拟网卡就失效. 注意:添加的虚拟网卡和原网卡物理地址是一样的。

方法2: 修改网卡配置文件

在ubuntu下,修改网卡的配置文件/etc/network/interfaces:

cat /etc/network/interfaces
auto enp49s0f0
iface enp49s0f0inet dhcp
auto enp49s0f0:1
iface enp49s0f0:1 inet staticaddress 10.10.1.103netmask 255.255.255.0gateway 10.10.1.1
auto enp49s0f0:2
iface enp49s0f0:2 inet staticaddress 10.10.2.103netmask 255.255.255.0gateway 10.10.2.1

保存后,重新加载配置文件才会生效,使用如下命令重启网卡:

service networking restart

优点: 重启服务器或者网卡配置不会丢失。

RHEL系统中,网卡IP配置的文件在/etc/sysconfig/network-scripts/下,文件分别为ehtx或ethx:x,执行命令如下:

#cd /etc/sysconfig/network-scripts/
#cp ifcfg-eth0 ifcfg-enp49s0f0:1
#vi ifcfg-enp49s0f0:1
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp49s0f0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp49s0f0
UUID=66fdb00f-848e-4c11-94e0-adfe988f5bd4
DEVICE=enp49s0f0
ONBOOT=yes
GATEWAY=10.10.1.1
IPADDR=10.10.1.2
PREFIX=24
DNS=114.114.114.114

修改其中的IPADDR部分为192.168.1.57,然后保存退出并启动该配置文件!

#ifup enp49s0f0:1  

方法3:创建tap

前两种方法都有一个特点,创建的网卡可有不同的ip地址,但是Mac地址相同,无法用来创建虚拟机。
使用命令tunctl添加虚拟网卡tap。

2 tunctl安装与使用

man tunctl 查看 tunctl 手册,用法如下:

Synopsis
tunctl [ OPTIONS ] [ -u owner ] [-g group] [ -t device-name ]
  • -u 参数指定用户名,表明这个接口只受该用户控制,这个接口发生的事不会影响到系统的接口。
  • -g 指定一组用户
  • -t 指定要创建的 tap/tun 设备名。

[OPTIONS] 部分:

  • -b 简单打印创建的接口名字
  • -n 创建 tun 设备
  • -p 创建 tap 设备,默认创建该设备
  • -f tun-clone-device 指定 tun 设备对应的文件名,默认是 /dev/net/tun,有些系统是 /dev/misc/net/tun
  • -d interfacename 删除指定接口

使用

常见用法:

默认创建 tap 接口:

tunctl

以上等价于 tunctl -p

为用户 user 创建一个 tap 接口:

# tunctl -u user

创建 tun 接口:

tunctl -n

为接口配置 IP 并启用:

# ifconfig tap0 192.168.0.254 up

为接口添加路由:

# route add -host 192.168.0.1 dev tap0

删除接口:

# tunctl -d tap0

ip tuntap

安装

命令行输入 ip help 查看 ip 命令是否支持 tuntap 工具,支持的话就会显示 tuntap 选项:

[root@localhost ~]# ip help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }ip [ -force ] -batch filename
where  OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |netns | l2tp | tcp_metrics | token }

不支持就请升级或下载最新的 iproute2 工具包,或者使用上面介绍的 tunctl 工具。

使用

输入 ip tuntap help 查看详细使用命令:

[root@localhost ~]# ip tuntap help
Usage: ip tuntap { add | del } [ dev PHYS_DEV ][ mode { tun | tap } ] [ user USER ] [ group GROUP ][ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ]Where: USER  := { STRING | NUMBER }GROUP := { STRING | NUMBER }

常见用法:

创建 tap/tun 设备:

ip tuntap add dev tap0 mod tap # 创建 tap
ip tuntap add dev tun0 mod tun # 创建 tun

删除 tap/tun 设备:

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

PS: usergroup 参数和 tunctl 的 -u、 -g 参数是一样的。

以上两个工具,我们更推荐使用 ip tuntap,一个是因为 iproute2 更全更新,已经逐步在替代老旧的一些工具,另一个是因为 tunctl 在某些 Debian 类的系统上支持不全。

总结

tunctlip tuntap 的常见使用方式。

2.1 安装yum  install uml-utilities

[root@localhost ~]# cat /etc/yum.repos.d/nux-misc.repo
[nux-misc]
name=Nux Misc
baseurl=http://li.nux.ro/download/nux/misc/el7/x86_64/
enabled=1
gpgcheck=0
gpgkey=http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

2.2 使用tunctl

NAME
       tunctl — create and manage persistent TUN/TAP interfaces
SYNOPSIS
       tunctl [-f tun-clone-device]  [-u owner]  [-t device-name]
       tunctl [-f tun-clone-device]  -d device-name
DESCRIPTION
       This manual page documents briefly the tunctl command.
       This  manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual
       page.  Instead, it has documentation in HTML format; see below.
        tunctl allows the host sysadmin to preconfigure a TUN/TAP device for use by a particular user. That user may open  and
       use the device, but may not change any aspects of the host side of the interface.
USAGE
        To create an interface for use by a particular user, invoke tunctl without the -d option:
        tunctl -u someuser       #Set 'tap0' persistent and owned by 'someuser'
        Then, configure the interface as normal:
        ifconfig tap0 192.168.0.254 up
        route add -host 192.168.0.253 dev tap0
        bash -c 'echo 1 > /proc/sys/net/ipv4/conf/tap0/proxy_arp'
        arp -Ds 192.168.0.253 eth0 pub

To delete the interface, use the -d option:
       tunctl -d tap0    #Set 'tap0' nonpersistent

3 TUN/TAP

tun/tap 驱动程序实现了虚拟网卡的功能, tun表示虚拟的是点对点设备,tap表示虚拟的是以太网设备,这两种设备针对网络包实施不同的封装。 利用tun/tap 驱动,可以将tcp/ip协议栈处理好的网络分包传给任何一个使用tun/tap驱动的进程,由进程重新处理后再发到物理链路中。

3.1 Tun/Tap驱动程序工作原理

做为虚拟网卡驱动,Tun/Tap驱动程序的数据接收和发送并不直接和真实网卡打交道, 而是 在Linux内核中添加了一个TUN/TAP虚拟网络设备的驱动程序和一个与之相关连的字符设备 /dev/net/tun,字符设备tun作为用户空间和内核空间交换数据的接口。
    当内核将数据包发送到虚拟网络设备时,数据包被保存在设备相关的一个队 列中,直到用户空间程序通过打开的字符设备tun的描述符读取时,它才会被拷贝到用户空间的缓冲区中,其效果就相当于,数据包直接发送到了用户空间。通过 系统调用write发送数据包时其原理与此类似。
    在linux下,要实现 内核空间 和 用户空间 数据的交互,有多种方式:可以通用socket创建特殊套接字,利用套接字实现数据交互;通过proc文件系统创建文件来进行数据交互;还可以使用设备文件的方式,访问设备文件会调用设备驱动相应的例程,设备驱动本身就是 内核空间 和 用户空间 的一个接口, Tun/tap驱动就是利用设备文件实现 用户空间 和 内核空间 的数据交互

从结构上来说,Tun/tap驱动并不单纯是实现网卡驱动,同时它还实现了字符设备驱动部分。以字符设备的方式连接用户空间和内核空间。
    Tun/tap 驱动程序中包含两个部分,一部分是字符设备驱动,还有一部分是网卡驱动部分。利用网卡驱动部分接收来自TCP/IP协议栈的网络分包并发送或者反过来将接收到的网络分包传给协议栈处理,而字符驱动部分则将网络分包在 用户空间和内核空间 之间传送,模拟物理链路的数据接收和发送。Tun/tap驱动很好的实现了两种驱动的结合。

3.2 设置

3.2.1 确认内核是否支持tun/tap

确认内核是否有tun模块

  [root@hunterfu]# modinfo tunfilename:       /lib/modules/2.6.34.7-56.fc13.i686.PAE/kernel/drivers/net/tun.koalias:          char-major-10-200license:        GPLauthor:         (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>description:    Universal TUN/TAP device driversrcversion:     880DE258930FE60D765B735depends:        vermagic:       2.6.34.7-56.fc13.i686.PAE SMP mod_unload 686 

加载内核模块

  [root@hunterfu ~]#  modprobe tun[root@hunterfu ~]# lsmod | grep tuntun                    10548  1 

执行以上命令后,出现如上输出,说明模块加载成功

3.2.2 创建和配置虚拟网卡

确认是否有tunctl命令,如果没有通过yum安装即可
apt-get install  uml-utilities  或 yum install tunctl
创建虚拟网卡设备
tunctl -t tap0 -u root
设置虚拟网卡
ifconfig tap0 192.168.0.1  netmask 255.255.255.0 promisc
经过如上操作后,虚拟网卡已经建立和配置好了。

3.2.3 作为系统服务随系统自动启动创建虚拟网卡

编写配置脚本(符合chkconfig规范)编写配置脚本(符合chkconfig规范)

[root@hunterfu ~]# cat /etc/init.d/config_tap #!/bin/bash## config_tap          Start up the tun/tap virtual nic## chkconfig: 2345 55 25USER="root"TAP_NETWORK="192.168.0.1"TAP_DEV_NUM=0DESC="TAP config"do_start() {if [ ! -x /usr/sbin/tunctl ]; thenecho "/usr/sbin/tunctl was NOT found!"exit 1fitunctl -t tap$TAP_DEV_NUM -u rootifconfig tap$TAP_DEV_NUM ${TAP_NETWORK}  netmask 255.255.255.0 promiscifconfig tap$TAP_DEV_NUM}do_stop() {ifconfig tap$TAP_DEV_NUM down }do_restart() {do_stopdo_start}check_status() {ifconfig tap$TAP_DEV_NUM }case $1 in start)    do_start;;stop)     do_stop;;restart)  do_restart;;status)echo "Status of $DESC: "check_statusexit "$?";;*)echo "Usage: $0 {start|stop|restart|status}"exit 1 esac

可以根据具体需求修改此脚本
加入到系统服务中

  [root@hunterfu ~]# chkconfig --add config_tap [root@hunterfu ~]# chkconfig --level 345 config_tap on

操作完成后,就可以像其他标准服务一样,通过 service config_tap start 来进行创建和启动操作

4 tunctl添加tap并用brctl添加到网桥

root@host# ifconfig -a
eth0      Link encap:Ethernet  HWaddr fa:16:3e:7b:4e:e1inet addr:192.168.33.24  Bcast:192.168.47.255  Mask:255.255.240.0inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1RX packets:5922 errors:0 dropped:0 overruns:0 frame:0TX packets:2002 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:503405 (503.4 KB)  TX bytes:322612 (322.6 KB)lo        Link encap:Local Loopbackinet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)root@host# tunctl
Set 'tap0' persistent and owned by uid 0
root@host# ifconfig -a
eth0      Link encap:Ethernet  HWaddr fa:16:3e:7b:4e:e1inet addr:192.168.33.24  Bcast:192.168.47.255  Mask:255.255.240.0inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1RX packets:6089 errors:0 dropped:0 overruns:0 frame:0TX packets:2057 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:514735 (514.7 KB)  TX bytes:339978 (339.9 KB)lo        Link encap:Local Loopbackinet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap0      Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edBROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)root@host# tunctl
Set 'tap1' persistent and owned by uid 0
root@host# ifconfig -a
eth0      Link encap:Ethernet  HWaddr fa:16:3e:7b:4e:e1inet addr:192.168.33.24  Bcast:192.168.47.255  Mask:255.255.240.0inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1RX packets:6323 errors:0 dropped:0 overruns:0 frame:0TX packets:2116 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:530988 (530.9 KB)  TX bytes:347960 (347.9 KB)lo        Link encap:Local Loopbackinet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap0      Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edBROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap1      Link encap:Ethernet  HWaddr 7e:6a:fc:31:18:35BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)root@host# brctl show
bridge name     bridge id               STP enabled     interfaces
root@host# ifconfig tap0 0.0.0.0
root@host# ifconfig tap1 0.0.0.0
root@host# ifconfig -a
eth0      Link encap:Ethernet  HWaddr fa:16:3e:7b:4e:e1inet addr:192.168.33.24  Bcast:192.168.47.255  Mask:255.255.240.0inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1RX packets:7246 errors:0 dropped:0 overruns:0 frame:0TX packets:2525 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:595705 (595.7 KB)  TX bytes:545518 (545.5 KB)lo        Link encap:Local Loopbackinet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap0      Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edUP BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap1      Link encap:Ethernet  HWaddr 7e:6a:fc:31:18:35UP BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)root@host# brctl addbr br-zhai
root@host# brctl addif br-zhai tap0
root@host# brctl addif br-zhai tap1
root@host# ifconfig -a
br-zhai   Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edBROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)eth0      Link encap:Ethernet  HWaddr fa:16:3e:7b:4e:e1inet addr:192.168.33.24  Bcast:192.168.47.255  Mask:255.255.240.0inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1RX packets:7515 errors:0 dropped:0 overruns:0 frame:0TX packets:2616 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:615539 (615.5 KB)  TX bytes:561216 (561.2 KB)lo        Link encap:Local Loopbackinet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap0      Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edUP BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap1      Link encap:Ethernet  HWaddr 7e:6a:fc:31:18:35UP BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)root@host# brctl show
bridge name     bridge id               STP enabled     interfaces
br-zhai         8000.7e13f129c0ed       no              tap0tap1
root@host# ifconfig br-zhai 192.168.9.1 up
root@host# ifconfig br-zhai
br-zhai   Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edinet addr:192.168.9.1  Bcast:192.168.9.255  Mask:255.255.255.0UP BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
root@host# brctl showmacs br-zhai
port no mac addr                is local?       ageing timer1     7e:13:f1:29:c0:ed       yes                0.002     7e:6a:fc:31:18:35       yes                0.00
root@host# brctl
Usage: brctl [commands]
commands:addbr           <bridge>                add bridgedelbr           <bridge>                delete bridgeaddif           <bridge> <device>       add interface to bridgedelif           <bridge> <device>       delete interface from bridgehairpin         <bridge> <port> {on|off}        turn hairpin on/offsetageing       <bridge> <time>         set ageing timesetbridgeprio   <bridge> <prio>         set bridge prioritysetfd           <bridge> <time>         set bridge forward delaysethello        <bridge> <time>         set hello timesetmaxage       <bridge> <time>         set max message agesetpathcost     <bridge> <port> <cost>  set path costsetportprio     <bridge> <port> <prio>  set port priorityshow            [ <bridge> ]            show a list of bridgesshowmacs        <bridge>                show a list of mac addrsshowstp         <bridge>                show bridge stp infostp             <bridge> {on|off}       turn stp on/offroot@host# ifconfig tap0 promisc
root@host# ifconfig
br-zhai   Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edinet addr:192.168.9.1  Bcast:192.168.9.255  Mask:255.255.255.0UP BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)eth0      Link encap:Ethernet  HWaddr fa:16:3e:7b:4e:e1inet addr:192.168.33.24  Bcast:192.168.47.255  Mask:255.255.240.0inet6 addr: fe80::f816:3eff:fe7b:4ee1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1RX packets:115463 errors:0 dropped:0 overruns:0 frame:0TX packets:6834 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:11942923 (11.9 MB)  TX bytes:1083602 (1.0 MB)lo        Link encap:Local Loopbackinet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap0      Link encap:Ethernet  HWaddr 7e:13:f1:29:c0:edUP BROADCAST PROMISC MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)tap1      Link encap:Ethernet  HWaddr 7e:6a:fc:31:18:35UP BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

参考:
1 Linux操作系统下Virtual Box的网络设置:http://www.51cto.com/art/200709/56461.htm

Linux

多网卡绑定、

IP

别名

2 Linux多网卡绑定、IP别名:https://wenku.baidu.com/view/6a4c0e6f31126edb6f1a10a4.html

https://blog.csdn.net/zhaihaifei/article/details/23168621

======================================================

brctl相关

以桥接的方式搭建虚拟机网络,其优势是可以将网络中的虚拟机看作是与主机同等地位的服务器。

在原本的局域网中有两台主机,现在要在CentOS(以下简称HOST)中搭建虚拟机,并使得虚拟机能够处于与Win7和HOST相同的网络环境中。

[root@localhost network-scripts]# cat ifcfg-enp49s0f0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp49s0f0
UUID=66fdb00f-848e-4c11-94e0-adfe988f5bd4
DEVICE=enp49s0f0
ONBOOT=yes
GATEWAY=10.10.1.1
IPADDR=10.10.1.2
PREFIX=24
DNS=114.114.114.114

配置桥接

[root@localhost network-scripts]# cat ifcfg-enp49s0f0
TYPE=Ethernet
BRIDGE=br0
NAME=enp3s0
UUID=99244a4d-8cac-4023-9a09-8e50c547cd3a
DEVICE=enp49s0f0
ONBOOT=yes

同时,在相同目录下拷贝一份该文件,并命名为 ifcfg-br0:

cp /etc/sysconfig/network-scripts/ifcfg-enp49s0f0 /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_AUTOCONF=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=br0
#UUID=99244a4d-8cac-4023-9a09-8e50c547cd3a
DEVICE=br0
#HWADDR=b0:6e:bf:bb:12:ad#static assignment
ONBOOT=yes
BOOTPROTO=staticIPADDR=192.168.0.251
GATEWAY=192.168.0.1
NETMASK=255.255.255.0
systemctl restart network.service

配置虚拟网络

使用如下命令打开KVM管理工具:

virt-manager

在【编辑】菜单中选择【连接详情】,打开如下窗口:网络接口里面的信息就是/etc/sysconfig/network-scripts/下面的网络配置文件

选择【网络接口】这个Tab,将br0接口给停止掉,即左侧下方红色的大叉叉,注意不是圆圈的叉叉,那个是删除,此处不要删除。

然后选择【虚拟网络】这个Tab,将原本的一个default网络给停止并删除掉,然后重新创建一个虚拟网络,创建过程如下:

https://www.cnblogs.com/weilu2/p/kvm_bridge_centos7.html参考

brctl addbr br0

brctl addif br0 enp49s0f0

ifconfig enp49s0f0 0.0.0.0 up

ifconfig  br0 10.10.1.2 netmask 255.255.255.0 up

route add default gw 10.10.1.1

brctl tunctl 虚拟网卡 桥接相关推荐

  1. virtualbox 创建桥接网络_VirtualBox 配置虚拟网卡(桥接),实现主机-虚拟机网络互通(图文教程)...

    网上搜出来的比较乱,讲的不明不白,因此根据自己弄过一次,确认可行的方式,做个备份,方便日后查阅. 环境: 在Oracle VM VirtualBox中安装的Ubuntu,具体版本名是:ubuntu-1 ...

  2. Dynamips基础教程系列---与本地网卡桥接

    一.Dynamips与本地网卡桥接 其实这是一个老问题,我在dynamips之入门篇(dynamipsGUI)(点击浏览)文章中也有讲解,可能因为篇幅有限,没有深入,给刚入门的新手带了不便,敬请原谅. ...

  3. Kali虚拟机桥接模式设置和虚拟网卡问题

    前言 Kali虚拟机网络配置问题,由于网络桥接模式出现问题,记录于此. ​ 问题1:桥接模式设置后,无法获取IP. ​ 问题2:Vmware 虚拟网卡在主机上消失. 一.Kali桥接模式设置 选择 虚 ...

  4. linux虚拟网卡tun,Centos7 创建虚拟网卡(tun/tap)

    创建网卡.创建网桥并建立桥接 [root@kolla ~]# cat create.sh create_br(){ tunctl -t storage -u root brctl addbr virb ...

  5. ubuntu删除虚拟网卡

    查看网卡信息 ifconfig 删除虚拟网卡 tunctl -d 网卡名 删除虚拟网桥 ifconfig <网桥名> down --停用网桥 brctl delbr <网桥名> ...

  6. Ubuntu 删除虚拟网卡/网桥的命令

    ubuntu下删除虚拟网卡/网桥的命令 刪除虚拟网卡 tunctl -d <虚拟网卡名> 刪除虚拟网桥 ifconfig <网桥名> down brctl delbr < ...

  7. linux上使用tun/tap设备模拟一个虚拟网卡,并将该虚拟网卡连接到新创建的网桥上

    目录 linux上使用tun/tap设备模拟一个虚拟网卡,并将该虚拟网卡连接到新创建的网桥上 一.tun/tap设备简介 二.在linux上使用tun/tap设备模拟一个虚拟网卡 三. 创建网桥连接到 ...

  8. 虚拟机无法使用网卡桥接模式

    重装了好几遍操作系统,换了两个虚拟机,差点怀疑人生-- 最终的原因竟然是win10!!! 1.执行WIN+R 输入services.msc,打开服务管理器(回车). 2.找到Device Instal ...

  9. 虚拟网卡技术-VETH、MACVLAN、IPVLAN

    Linux的网卡驱动中内含了很多"虚拟网卡".早先的文章曾经详细分析过tun,ifb等虚拟网卡,类似的思路,在虚拟化大行其道的趋势下,Linux源码树中不断增加对"网络虚 ...

  10. centos 6 KVM 网卡桥接配置

    一. 网卡桥接前准备 1.软件支持: # rpm -qa bridge-utils # yum install bridge-utils       确保软件包已安装 2. 关闭NetworkMana ...

最新文章

  1. 用《R数据科学》学习一套数据处理语法
  2. 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATI
  3. java 整合hadoop_Spark 如何摆脱java双亲委托机制优先从用户jar加载类?
  4. 苦大仇深--写给想做产品的朋友们(二)
  5. 【MM】更改供应商账户组
  6. linux 内存越界判断_LINUX 共享内存越界
  7. 统计代码行数_推荐一波代码量、行数、提交量、作者等全维度统计神器
  8. SQL Server 2000 索引视图提高性能2
  9. Linux锁定和解锁用户
  10. WPF 读取Docx文件并显示(附下载链接)
  11. 北大计算机基础与应用,北大16秋《计算机基础与应用-第六组》在线作业
  12. jspsmartupload上传文件 servlet得不到jsp参数
  13. 三款好用的前端代码编辑器推荐
  14. python黑客编程-[分享]Python黑帽子 黑客与渗透测试编程之道PDF和文章内代码【全】...
  15. labwindows计时器
  16. [音乐] 逆转裁判1~4 追求 链接
  17. LaTex bib引用知网论文NoteExpress格式文献 —— cnki2bib
  18. java实现dwg转pdf
  19. 重新定义汽车人机界面开发,Unity HMI模板正式开放使用
  20. SP(软件过程)的发展历程2:计划驱动软件开发过程时代

热门文章

  1. 计算机考试操作步骤,全国计算机等级考试网报操作流程
  2. matlab imagesc 平滑,在matlab中,如何使用imagesc在2D热图中“平滑”像素
  3. 高德地图 html5,高德地图API发布HTML5矢量地图渲染引擎[图]
  4. 什么是城市大数据?大数据如何应用在智慧城市中?
  5. windows cl命令行编译和nmake
  6. SVN 创建分支,分支与主干的合并
  7. idea 主题文字大小修改
  8. JDK动态代理与CGLIB动态代理
  9. wamp添加mysql版本_最新版PHPWAMP自定义添加PHP版本教程,支持无限添加PHP和Mysql版本...
  10. python基础语法记录