-1

I have home server with Debian installed

When I turn on openvpn it creates new interface - tun0

It also adds some routing rules for that interface, including 0.0.0.0/1 via 192.168.101.1 dev tun0, but I always delete this rule to make eth0 default interface so everything goes via it by default

I want to setup that server as gateway, and make all data forward from eth0 to tun0

Then I could just change default gateway to server's ip on any device in lan to use vpn

And the question is how can I do this?

stek29
  • 119
  • 1
  • 5

1 Answers1

1

I found answer to my question:

  • Start OpenVPN:

openvpn --config /path/to/config.file &

  • Wait until it successfully connects:

until ip l sh tun0 >/dev/null 2>&1 ; do sleep 1; done

  • Delete rule which makes tun0 default interface:

ip route del 0.0.0.0/1 via 192.168.101.1 dev tun0

  • Enable ip forwarding:

sysctl -w net.ipv4.ip_forward=1

  • Enable and configure NAT:

iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT

stek29
  • 119
  • 1
  • 5