Centos7 創建虛擬網卡(tun/tap)

創建網卡、創建網橋並建立橋接

[root@kolla ~]# cat create.sh
create_br(){
    tunctl -t storage -u root
    brctl addbr virbr2
    brctl addif virbr2 storage
    ifconfig virbr2 10.10.1.1 netmask 255.255.255.0 up
    brctl stp  virbr2 on
}
delete_br(){
    ifconfig virbr1  down
    brctl delbr virbr1
    tunctl -d manager
}

create_br
#delete_br

 

1. 確認內核是否支持tun/tap,確認內核是否有tun模塊
  [root@guanxiaojue]# modinfo tun
  filename:       /lib/modules/2.6.34.7-56.fc13.i686.PAE/kernel/drivers/net/tun.ko
  alias:          char-major-10-200
  license:        GPL
  author:         (C) 1999-2004 Max Krasnyansky <[email protected]>
  description:    Universal TUN/TAP device driver
  srcversion:     880DE258930FE60D765B735
  depends:        
  vermagic:       2.6.34.7-56.fc13.i686.PAE SMP mod_unload 686 
如上所示,則說明內核支持tun/tap虛擬網卡

2.加載內核模塊 
  [root@guanxiaojue ~]#  modprobe tun
  [root@guanxiaojue ~]# lsmod | grep tun
  tun                    10548  1 
//如上顯示,則說明內核模塊加載成功

3.添加centos7的tunctl源
(1)創建下面的文件: /etc/yum.repos.d/nux-misc.repo:
    [nux-misc]
    name=Nux Misc
    baseurl=http://li.nux.ro/download/nux/misc/el7/x86_64/
    enabled=0
    gpgcheck=1
    gpgkey=http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
(2)安裝tunctl rpm包
    # yum --enablerepo=nux-misc install tunctl

4.使用tunctl新建虛擬網卡
(1)創建網卡的設備文件:
    [root@guanxiaojue ~]# tunctl -t tap0 -u root//如果是非root用戶則需要sudo下
(2)設置虛擬網卡:
    [root@guanxiaojue ~]# ifconfig tap0 192.168.0.1  netmask 255.255.255.0 promisc
經過如上操作後,虛擬網卡已經建立和配置好了。


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章