I rented a server and configured it as a VPN server. At home I have my privat network and a guest network. Both networks have their own Raspberry Pi, they are routing the hole traffic from their networks true the VPN tunnel to the internet. But I like to have a port forwarding from one server to the other because guests should be able to do reach a PC using specified ports.
iptables -t nat -A POSTROUTING -o venet0 -s 10.8.0.0/24 -p tcp --sport 1234 -j SNAT --to 10.8.1.0/24
iptables -t nat -A POSTROUTING -o venet0 -s 10.8.0.0/24 -j SNAT --to xxx.xxx.xxx.xxx
iptables -A INPUT -s 10.8.0.0/24 -d 10.8.1.0/24 -j DROP
iptables -A INPUT -s 10.8.0.0/24 -d 192.168.178.0/24 -j DROP
iptables -A INPUT -s 10.8.0.0/24 -p tcp --sport 1234 -d 10.8.1.0/24 -j ACCEPT
iptables -A INPUT -s 10.8.1.0/24 -p tcp --sport 1234 -d 10.8.0.0/24 -j ACCEPT
Could this code work? My idea is:
Only the traffic from the IP 10.8.0.0 and from the port 1234 will be routed to the IP 10.8.1.0. All the other ports get routed to the internet.
First I deny all traffic from 10.8.0.0 to 10.8.1.0 or 192.168.178.0/24. But traffic from the IP 10.8.0.0 and from port 1234 to 10.8.1.0 will be accepted.
What do you guys think?