S
S
Santa Claus162015-09-14 11:50:14
linux
Santa Claus16, 2015-09-14 11:50:14

How to forward port through openvpn?

Two jabber servers (vps). Both have only eth0 with external static ip and lo respectively. An openvpn (tun) tunnel has been raised between the servers. Nothing is written in ccd (an empty file), route and iroute are also not registered (there are no locales behind the servers). Both servers see each other perfectly, through tun, pings go, ssh works from one to the other.
Few configurations:
Server 1 - eth0 - xxx.xxx.xxx.xxx, tun0 - 10.8.37.1, iptables v1.4.14
Server 2 - eth0 - yyy.yyy.yyy.yyy, tun0 - 10.8.37.2, iptables v1.4.4
net .ipv4.ip_forward=1 - on both machines
The task is to forward the port from server2:5222 to server1:12001. In other words, to have access to 10.8.37.1:5222 via yyy.yyy.yyy.yyy:12001.
Records on server2 type:
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 12001 -j DNAT --to-destination 10.8.37.1:5222
iptables -A FORWARD -d 10.8.37.1/32 -p tcp -m tcp --dport 5222 -j ACCEPT
does not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SantaClaus16, 2015-09-14
@Santa Claus16

As a result, it worked like this:
iptables -t nat -A PREROUTING -d yyy.yyy.yyy.yyy -p tcp -m tcp --dport 12001 -j DNAT --to-destination 10.8.37.1:5222
iptables -t nat -A POSTROUTING -d 10.8.37.1 -p tcp -m tcp --dport 5222 -j SNAT --to-source 10.8.37.2

I
Ilyas, 2015-09-14
@IlyasR

Is forwarding enabled?
sysctl net.ipv4.ip_forward=1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question