How to change only the openvpn ip for outgoing traffic

This forum is for admins who are looking to build or expand their OpenVPN setup.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Post Reply
jamesfawcett
OpenVpn Newbie
Posts: 13
Joined: Thu Aug 04, 2011 4:18 pm

How to change only the openvpn ip for outgoing traffic

Post by jamesfawcett » Wed Sep 14, 2011 7:35 pm

hi everyone,

i have 6 ip addresses allocated to my server.
I use my server as an openvpn secure connection from all my laptops and home pc.

Currently i have the following line in my rc.local which sets up with traffic going out everytime i reboot my server:

Code: Select all

iptables -t nat -A POSTROUTING -j SNAT --to-source 83.***.***.213
That is my main server ip address. I would like to have my outgoing openvpn connection on a different ip, is it possible?
I have tried changing the code, to one of my other ip addresses, such as:

Code: Select all

iptables -t nat -A POSTROUTING -j SNAT --to-source 83.***.***.214
...but the problem is i have trouble with my cpanel licences etc messing up.
What i would like to know is it possible to change the command above, to just affect the openvpn traffic and nothing else?
or is there something i can add into my openvpn.conf instead to change the outgoing ip? i already have changed the incoming listening ip by using:

Code: Select all

local 83.***.***.211

thanks for any help you can give me :)

jamesfawcett
OpenVpn Newbie
Posts: 13
Joined: Thu Aug 04, 2011 4:18 pm

Re: How to change only the openvpn ip for outgoing traffic

Post by jamesfawcett » Wed Sep 14, 2011 9:42 pm

sorry to post again, i have just been playing arround with my old setup on the server which involves stunnel and squid.

In squid i can change the outgoing ip address for the traffic with the code:

Code: Select all

tcp_outgoing_address 83.***.***.121 ip1
if you put more than one tcp_outgoing_address, squid alternates between each ip address at every connect.
Is there no command like this in openvpn?

I also wondered if there is an openvpn equivilant of:

Code: Select all

httpd_suppress_version_string on
which is used to hide http headers (i think)

is there anything like this in openvpn?

if not, would it be a bad idea if i route openvpn through squid?
is that a silly idea? that would let me choose my outgoing ip address etc

thanks 8-)

User avatar
Bebop
Forum Team
Posts: 301
Joined: Wed Dec 15, 2010 9:24 pm

Re: How to change only the openvpn ip for outgoing traffic

Post by Bebop » Thu Sep 15, 2011 1:47 am

jamesfawcett wrote:is it possible to change the command above, to just affect the openvpn traffic and nothing else?

Something like:

Code: Select all

iptables -t nat -A POSTROUTING -s 10.8.1.0/24 -j SNAT --to-source 83.***.***.214
This should solve that part of the problem for you. Replace 10.8.1.0 with whatever subnet your VPN as assigning.

More info here: topic8559.html
The cure for boredom is curiosity

jamesfawcett
OpenVpn Newbie
Posts: 13
Joined: Thu Aug 04, 2011 4:18 pm

Re: How to change only the openvpn ip for outgoing traffic

Post by jamesfawcett » Thu Sep 15, 2011 8:22 am

excellent!! that is the main thing i needed, thank you!

i will give this a try now, thanks again :) :) :D

jamesfawcett
OpenVpn Newbie
Posts: 13
Joined: Thu Aug 04, 2011 4:18 pm

Re: How to change only the openvpn ip for outgoing traffic

Post by jamesfawcett » Thu Sep 15, 2011 8:44 am

Bebop wrote: Something like:

Code: Select all

iptables -t nat -A POSTROUTING -s 10.8.1.0/24 -j SNAT --to-source 83.***.***.214
this worked!

all sorted :)

thanks
james

Post Reply