Τετάρτη 7 Αυγούστου 2013

Configuring an openvpn bridge on CentOS

First, edit /etc/sysconfig/network-scripts/ifcfg-eth0
Remove, or comment the interfaces ip configuration and add it to the bridge:
DEVICE=eth0
#BOOTPROTO=static
HWADDR=70:72:BC:A3:21:51
ONBOOT=yes
#IPADDR=192.168.1.192
#NETMASK=255.255.255.0
#NETWORK=192.168.1.0
BRIDGE=br0
Edit /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
BOOTPROTO=static
ONBOOT=yes
TYPE=Bridge
IPADDR=192.168.1.192
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
#The follwing is of course optional
IPV6INIT=yes

restart network and check that the i/f is ok:
ifconfig br0


You have to create 2 custom scripts in order to add the tap interface in the bridge everytime your openvpn server is started and add the 2 follwing lines on your openvpn config:
up "/etc/openvpn/bridge-start.sh"
down-pre "/etc/openvpn/bridge-stop.sh"


bridge-start.sh
#!/bin/sh
/usr/sbin/brctl addif br0 $1
/sbin/ifconfig $1 up


bridge-stop.sh
/sbin/ifconfig $1 down
/usr/sbin/brctl delif br0 $


After your openvpn server is started, you may check that the interface is addes to the bridge:
brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.7072bca32151       no              tap0
                                                                       eth0