Skip to contentSkip to conversation

NAT and openvpn

DISCUSSION G. Skillen 5 participants 9 messages Mar 27, 2009 – Mar 28, 2009

lore
Share & tools
lore

G. Skillen

author
#0 lore raw

Hi,

I have set up a vpn (openvpn) from my home computer to a remote server, I have several unused public IPs on the server and I would like to know how to transparently send all traffic from e.g 123.123.123.123 (one of the spare public ips) to 10.8.0.2 (the vpn ip of my home machine), and vice versa i guess.

Basically my home ISP doesn't allow me any incoming connections so this would be a workaround for me to run a web/ftp server.

Thanks,
G

Signature · 1 line
G. Skillen <[email protected]>
#1 lore raw
Quoted 1 line

I have set up a vpn (openvpn) from my home computer to a remote server, I have several >unused public IPs on the server and I would like to know how to transparently send all >traffic from e.g 123.123.123.123 (one of the spare public ips) to 10.8.0.2 (the vpn ip >of my home machine), and vice versa i guess.

% iptables -t nat -A PREROUTING -s $VPNIP -j SNAT --to-source $PUBIP % iptables -t nat -A POSTROUTING -s $PUBIP -j DNAT --to-destination $VPNIP

That should do the trick for you for a general NAT, I'd suggest adding filtering, etc.

--
Jason Faulkner
Linux Systems Engineer
Mailtrust, a division of Rackspace

author
#2 lore raw
Quoted 2 lines

% iptables -t nat -A PREROUTING -s $VPNIP -j SNAT --to-source $PUBIP % iptables -t nat -A POSTROUTING -s $PUBIP -j DNAT --to-destination $VPNIP

Thanks for the reply ... when I try that I get:

	mothership:~# iptables -t nat -A PREROUTING -s 10.8.0.2 -j SNAT --to-source <ip omitted>
	iptables: Invalid argument

(same for the next line)

Any ideas?

Signature · 1 line
G. Skillen <[email protected]>
#4 lore raw

% iptables -t nat -A PREROUTING -s $VPNIP -j SNAT --to-source $PUBIP

Quoted 7 lines

% iptables -t nat -A POSTROUTING -s $PUBIP -j DNAT --to-destination $VPNIP

hanks for the reply ... when I try that I get:

	mothership:~# iptables -t nat -A PREROUTING -s 10.8.0.2 -j SNAT --to-source <ip omitted>
	iptables: Invalid argument
Quoted 10 lines · [email protected] wrote:
Quoted 2 lines

iptables: Invalid argument

Perhaps this? http://www.netfilter.org/documentation/FAQ/netfilter-faq-3.html#ss3.20

--
Jason Faulkner Linux Systems Engineer
Mailtrust, a division of Rackspace

Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

good morning guys:
DNAT
This target is only valid in the nat table, in the
PREROUTING and OUTPUT chains

SNAT
This target is only valid in the nat table, in the
POSTROUTING chain.

not the kernel suddenly breaking.
RTFM! :)

everybody sleeping? ;-)

greets

Mart

#5 lore raw
In reply to G. Skillen

http://iptables-tutorial.frozentux.net/iptables-tutorial.html

SNAT is only valid in POSTROUTING chain, DNAT - in PREROUTING.

These rules should be:

iptables -t nat -A PREROUTING -d $PUBIP -j DNAT --to-destination $VPNIP # for incoming traffic
iptables -t nat -A POSTROUTING -s $VPNIP -j SNAT --to-source $PUBIP # for outgoing traffic

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of G. Skillen
Sent: Saturday, March 28, 2009 5:52 AM
To: [email protected]
Cc: [email protected]
Subject: Re: NAT and openvpn

Quoted 2 lines

% iptables -t nat -A PREROUTING -s $VPNIP -j SNAT --to-source $PUBIP % iptables -t nat -A POSTROUTING -s $PUBIP -j DNAT --to-destination $VPNIP

Thanks for the reply ... when I try that I get:

	mothership:~# iptables -t nat -A PREROUTING -s 10.8.0.2 -j SNAT --to-source <ip omitted>
	iptables: Invalid argument

(same for the next line)

Any ideas?

Signature · 5 lines
G. Skillen <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
In reply to G. Skillen

Hi there,

Quoted 8 lines · G. Skillen

I have set up a vpn (openvpn) from my home computer to a remote server, I have several unused public IPs on the server and I would like to know how to transparently send all traffic from e.g 123.123.123.123 (one of the spare public ips) to 10.8.0.2 (the vpn ip of my home machine), and vice versa i guess.

Basically my home ISP doesn't allow me any incoming connections so this would be a workaround for me to run a web/ftp server.

Would it not make more sense to run the servers on the remote machine? The sytem you describe would be unnecessarily fragile.

--

73,
Ged.

author
#6 lore raw
In reply to Nikolay S. Rybaloff
Quoted 4 lines

These rules should be:

iptables -t nat -A PREROUTING -d $PUBIP -j DNAT --to-destination $VPNIP # for incoming traffic
iptables -t nat -A POSTROUTING -s $VPNIP -j SNAT --to-source $PUBIP # for outgoing traffic

hi,

these rules get added without any problems, but when i try to connect to connect to the http server i have running locally, it just times out. is there anything i should set up on the local machine?

thanks,

g

author
#8 lore raw
In reply to G.W. Haywood
Quoted 3 lines

Would it not make more sense to run the servers on the remote machine? The sytem you describe would be unnecessarily fragile.

i understand your concern; neither machines run anything critical though. i'm just tinkering for the sake of tinkering really (and to perhaps learn something new).

cheers,
g