IP Forwarding and Routing in Centos 6.6 and OpenVPN

If you want to forward all internet traffic through your openvpn connection and centos server apply the following:

nanow /etc/sysctl.conf
change net.ipv4.ip_forward = 1
sysctl -p
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle –F
iptables -t mangle –X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -I INPUT -j ACCEPT
iptables -I OUTPUT -o eth0 -d 0.0.0.0/0 -j ACCEPT
iptables -I INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

for OpenVz

iptables -I OUTPUT -o venet0:0 -d 0.0.0.0/0 -j ACCEPT
iptables -I INPUT -i venet0:0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o venet0 -j SNAT --to-source SERVER_WAN_IP
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source SERVER_WAN_IP

Save and Apply rules

service iptables save
service iptables restart
Categories: OpenVPN Tags: , , , ,
%d bloggers like this: