Skip to content

Commit 78f2140

Browse files
author
Dean Troyer
committed
Change vpn to bridged mode
1 parent de918e0 commit 78f2140

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

tools/install_openvpn.sh

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
# --server mode configures the host with a running OpenVPN server instance
1111
# --client mode creates a tarball of a client configuration for this server
1212

13+
# Get config file
14+
if [ -e localrc.vpn ]; then
15+
. localrc.vpn
16+
fi
17+
1318
# VPN Config
1419
VPN_SERVER=${VPN_SERVER:-`ifconfig eth0 | awk "/inet addr:/ { print \$2 }" | cut -d: -f2`} # 50.56.12.212
1520
VPN_PROTO=${VPN_PROTO:-tcp}
1621
VPN_PORT=${VPN_PORT:-6081}
1722
VPN_DEV=${VPN_DEV:-tun}
23+
VPN_BRIDGE=${VPN_BRIDGE:-br0}
1824
VPN_CLIENT_NET=${VPN_CLIENT_NET:-172.16.28.0}
1925
VPN_CLIENT_MASK=${VPN_CLIENT_MASK:-255.255.255.0}
26+
VPN_CLIENT_DHCP="${VPN_CLIENT_DHCP:-172.16.28.1 172.16.28.254}"
2027
VPN_LOCAL_NET=${VPN_LOCAL_NET:-10.0.0.0}
2128
VPN_LOCAL_MASK=${VPN_LOCAL_MASK:-255.255.0.0}
2229

@@ -39,7 +46,8 @@ if [ -z $1 ]; then
3946
fi
4047

4148
# Install OpenVPN
42-
if [ ! -x `which openvpn` ]; then
49+
VPN_EXEC=`which openvpn`
50+
if [ -z "$VPN_EXEC" -o ! -x "$VPN_EXEC" ]; then
4351
apt-get install -y openvpn bridge-utils
4452
fi
4553
if [ ! -d $CA_DIR ]; then
@@ -73,21 +81,49 @@ do_server() {
7381
(cd $CA_DIR/keys;
7482
cp $NAME.crt $NAME.key ca.crt dh1024.pem ta.key $VPN_DIR
7583
)
84+
cat >$VPN_DIR/br-up <<EOF
85+
#!/bin/bash
86+
87+
BR="$VPN_BRIDGE"
88+
TAP="\$1"
89+
90+
for t in \$TAP; do
91+
openvpn --mktun --dev \$t
92+
brctl addif \$BR \$t
93+
ifconfig \$t 0.0.0.0 promisc up
94+
done
95+
EOF
96+
chmod +x $VPN_DIR/br-up
97+
cat >$VPN_DIR/br-down <<EOF
98+
#!/bin/bash
99+
100+
BR="$VPN_BRIDGE"
101+
TAP="\$1"
102+
103+
for i in \$TAP; do
104+
brctl delif \$BR $t
105+
openvpn --rmtun --dev \$i
106+
done
107+
EOF
108+
chmod +x $VPN_DIR/br-down
76109
cat >$VPN_DIR/$NAME.conf <<EOF
77110
proto $VPN_PROTO
78111
port $VPN_PORT
79112
dev $VPN_DEV
113+
up $VPN_DIR/br-up
114+
down $VPN_DIR/br-down
80115
cert $NAME.crt
81116
key $NAME.key # This file should be kept secret
82117
ca ca.crt
83118
dh dh1024.pem
84119
duplicate-cn
85-
server $VPN_CLIENT_NET $VPN_CLIENT_MASK
120+
#server $VPN_CLIENT_NET $VPN_CLIENT_MASK
121+
server-bridge $VPN_CLIENT_NET $VPN_CLIENT_MASK $VPN_CLIENT_DHCP
86122
ifconfig-pool-persist ipp.txt
87123
push "route $VPN_LOCAL_NET $VPN_LOCAL_MASK"
88124
comp-lzo
89125
user nobody
90-
group nobody
126+
group nogroup
91127
persist-key
92128
persist-tun
93129
status openvpn-status.log
@@ -121,7 +157,7 @@ remote $VPN_SERVER $VPN_PORT
121157
resolv-retry infinite
122158
nobind
123159
user nobody
124-
group nobody
160+
group nogroup
125161
persist-key
126162
persist-tun
127163
comp-lzo

0 commit comments

Comments
 (0)