brctl 設定橋接器

  1. 查看目前的橋接只有 KVM 虛擬機使用的 virbr0。
    [root@dyw219 ~]# brctl show
    bridge name	bridge id		STP enabled	interfaces
    virbr0		8000.fe54000af4cf	yes		vnet0
    							vnet1
    							vnet3
    							vnet4
    							vnet5
    							vnet6
    
  2. 增加 br0 橋接器做為 VPN hub 使用。
    [root@dyw219 ~]# brctl addbr br0
    [root@dyw219 ~]# brctl show
    bridge name	bridge id		STP enabled	interfaces
    br0		8000.00ac3da01692	no		
    virbr0		8000.fe54000af4cf	yes		vnet0
    							vnet1
    							vnet3
    							vnet4
    							vnet5
    							vnet6
    
  3. 增加 br0 橋接器連接的網卡 eth0。
    [root@dyw219 ~]# brctl addif br0 eth0
    [root@dyw219 ~]# brctl show
    bridge name	bridge id		STP enabled	interfaces
    br0		8000.00ac3da01692	no		eth0
    virbr0		8000.fe54000af4cf	yes		vnet0
    							vnet1
    							vnet3
    							vnet4
    							vnet5
    							vnet6
    
  4. 增加 br0 橋接器連接的網卡 eth0。
    [root@dyw219 ~]# brctl addif br0 eth0
    [root@dyw219 ~]# brctl show
    bridge name	bridge id		STP enabled	interfaces
    br0		8000.00ac3da01692	no		eth0
    virbr0		8000.fe54000af4cf	yes		vnet0
    							vnet1
    							vnet3
    							vnet4
    							vnet5
    							vnet6
    
  5. 查看網卡出現 tap_eth0
    [root@dyw219 ~]# ifconfig | grep ^[a-z] | awk '{print $1}'
    br0
    eth0
    eth1
    lo
    tap_eth0
    virbr0
    vnet0
    vnet1
    vnet3
    vnet4
    vnet5
    vnet6
    
  6. 增加 br0 橋接器連接的網卡 tap_eth0
    [root@dyw219 ~]# brctl addif br0 eth0
    [root@dyw219 ~]# brctl show
    bridge name	bridge id		STP enabled	interfaces
    br0		8000.00ac8e8ec395	no		eth0
    							tap_eth0
    virbr0		8000.fe54000af4cf	yes		vnet0
    							vnet1
    							vnet3
    							vnet4
    							vnet5
    							vnet6
    
  7. 編輯橋接器 br0,網卡 eth0 及 tap_eth0 設定檔。
    [root@dyw219 ~]# cd /etc/sysconfig/network-scripts/
    [root@dyw219 network-scripts]# cp ifcfg-eth0 ifcfg-br0 
    [root@dyw219 network-scripts]# cp ifcfg-eth0 ifcfg-tap_eth0
    
    [root@dyw219 network-scripts]# vim ifcfg-br0 
    [root@dyw219 network-scripts]# cat ifcfg-br0 
    DEVICE="br0"
    IPADDR=192.168.1.254
    NETMASK=255.255.255.0
    GATEWAY=163.17.27.219
    DNS1=120.110.21.249
    DNS2=8.8.8.8
    ONBOOT="yes"
    TYPE=Bridge
    
    [root@dyw219 network-scripts]# vim ifcfg-eth0 
    [root@dyw219 network-scripts]# cat ifcfg-eth0 
    DEVICE="eth0"
    ONBOOT="yes"
    BRIDGE=br0
    TYPE=Ethernet
    
    [root@dyw219 network-scripts]# vim ifcfg-tap_eth0 
    [root@dyw219 network-scripts]# cat ifcfg-tap_eth0 
    DEVICE="tap_eth0"
    ONBOOT="yes"
    BRIDGE=br0
    TYPE=Ethernet
    
  8. 重新啟動網路。
    [root@dyw219 network-scripts]# /etc/init.d/network restart
    
  9. 再使用 vpncmd 命令進入 hub vpn 管理模式,查看 hub VPN 的 IP 多了一個橋接 IP 192.168.1.254,表示只要 vpn client 連線的 network adapter 設定 192.168.1.0/24 的網段就可以直接連線 VPN server 端的 192.168.1.0/24 網段機器。
    VPN Server/VPN>iptable
    IpTable command - Get the IP Address Table Database
    Item        |Value
    ------------+------------------------
    ID          |1358754158
    Session Name|SID-LOCALBRIDGE-3
    IP Address  |192.168.1.254
    Created at  |2016-05-17 08:03:50
    Updated at  |2016-05-17 08:03:54
    Location    |On 'dyw219'
    ------------+------------------------
    ID          |804511970
    Session Name|SID-SECURENAT-1
    IP Address  |192.168.30.1
    Created at  |2016-05-17 07:30:31
    Updated at  |2016-05-17 08:03:55
    Location    |On 'dyw219'
    ------------+------------------------
    ID          |3996354065
    Session Name|SID-LOCALBRIDGE-3
    IP Address  |fe80::2ac:3dff:fea0:1692
    Created at  |2016-05-17 08:01:49
    Updated at  |2016-05-17 08:03:54
    Location    |On 'dyw219'
    The command completed successfully.