I set up an OpenVPN server on my VPS, using this guide: http://vpsnoc.com/blog/how-to-install-openvpn-on-a-debianubuntu-vps-instantly/

And I can connect to it without problems. Connect, that is, because no traffic is being redirected. When I try to load a webpage when connected to the vpn I just get an error.

This is the config file it generated:

dev tun
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
push "route 10.8.0.0 255.255.255.0"
push "redirect-gateway"
comp-lzo
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
group daemon
daemon

This is my iptables.conf

# Generated by iptables-save v1.4.4 on Sat May  7 13:09:44 2011
*raw
:PREROUTING ACCEPT [37938267:10998335127]
:OUTPUT ACCEPT [35616847:14165347907]
COMMIT
# Completed on Sat May  7 13:09:44 2011
# Generated by iptables-save v1.4.4 on Sat May  7 13:09:44 2011
*nat
:PREROUTING ACCEPT [794948:91051460]
:POSTROUTING ACCEPT [1603974:108147033]
:OUTPUT ACCEPT [1603974:108147033]
-A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
-A POSTROUTING -s 10.8.0.0/24 -o eth1 -j MASQUERADE
-A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE
COMMIT
# Completed on Sat May  7 13:09:44 2011
# Generated by iptables-save v1.4.4 on Sat May  7 13:09:44 2011
*mangle
:PREROUTING ACCEPT [37938267:10998335127]
:INPUT ACCEPT [37677226:10960834925]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [35616847:14165347907]
:POSTROUTING ACCEPT [35680187:14169930490]
COMMIT
# Completed on Sat May  7 13:09:44 2011
# Generated by iptables-save v1.4.4 on Sat May  7 13:09:44 2011
*filter
:INPUT ACCEPT [37677226:10960834925]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [35616848:14165347947]
-A INPUT -i eth0 -j LOG --log-prefix "BANDWIDTH_IN:" --log-level 7
-A FORWARD -o eth0 -j LOG --log-prefix "BANDWIDTH_OUT:" --log-level 7
-A FORWARD -i eth0 -j LOG --log-prefix "BANDWIDTH_IN:" --log-level 7
-A OUTPUT -o eth0 -j LOG --log-prefix "BANDWIDTH_OUT:" --log-level 7
COMMIT
# Completed on Sat May  7 13:09:44 2011
link|improve this question

64% accept rate
Is the config you posted for your VPN server or client? Can you post both? What is the error you received when trying to load a webpage? – tehfink May 7 '11 at 22:52
feedback

2 Answers

Fix for Ubuntu/Debian

edit - /etc/openvpn/server.conf

add: push "redirect-gateway def1"

edit - /etc/sysctl.conf

add: net.ipv4.ip_forward=1

Add these rules to your Iptables:

iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT iptables -A FORWARD -j REJECT iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

Install dnsmasq - apt-get install dnsmasq

edit - /etc/openvpn/server.conf

add: push "dhcp-option DNS 10.8.0.1"

Reboot Server.

Server should now tunnel ipv4 and DNS traffic.

link|improve this answer
Hmm, dnsmasq doesn't want to start because "the" address is already in use. Is it talking about 10.8.0.1, my tun1 device? – skerit May 8 '11 at 21:11
Why not simply redefine the default route to use the VPN server as gateway ? – Kedare Jun 28 '11 at 19:28
feedback

You should try this :

edit server.conf and add :

push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"

Router config

echo "1" > /proc/sys/net/ipv4/ip_forward

Edit /etc/sysctl.conf and add

net.ipv4.ip_forward = 1

Then

sudo sh -c "iptables-save > /etc/iptables.rules"

REstart your VPN:

sudo service openvpn restart

This should worx

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.