Linode Forum Index Linode Forum
Linode Community Forums
 


OpenVPN and 2 Public IP Addresses

Click here to go to the original topic

 
       Linode Forum Index -> Linux Networking
Author Message
iWizardPro



Joined: 15 Jun 2011
Posts: 19

Posted: Tue Dec 27, 2011 11:12 pm    Post subject: OpenVPN and 2 Public IP Addresses  

Hello,

I just added a new IP address to my Linode and I am having some difficulties with setting which connection my OpenVPN server should forward network traffic through. Initially all my traffic was directed through 96.126.100.xxx, but upon adding another IP (50.116.1.xxx), all my traffic began going through that one instead. How do I go about specifying that my connections should go through 96.126.100.xxx?

My configuration for my network is as follows:

/etc/network/interfaces:
Code: # This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
  address 96.126.100.xxx
  netmask 255.255.255.0
  gateway 96.126.100.1

auto eth0:0
iface eth0:0 inet static
  address 50.116.1.xxx
  netmask 255.255.255.0
  gateway 50.116.1.1

/etc/rc.local:
Code: iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s 10.7.0.0/24 -j ACCEPT
iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT
iptables -A FORWARD -s 10.9.0.0/24 -j ACCEPT
iptables -A FORWARD -j REJECT
iptables -t nat -A POSTROUTING -s 10.7.0.0/24 -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.9.0.0/24 -o eth0 -j MASQUERADE

exit 0

Signed,
Ryan Tse
Back to top  
hoopycat



Joined: 30 Aug 2008
Posts: 1294
Location: Rochester, New York

Posted: Tue Dec 27, 2011 11:25 pm    Post subject:  

With IPv6 addresses, my usual approach is to add 'preferred_lft 0'. I can't recall if this works for IPv4, but if it does:

Code: auto eth0
iface eth0 inet static
  address 96.126.100.xxx
  netmask 255.255.255.0
  gateway 96.126.100.1
  up /sbin/ip addr add 50.116.1.xxx dev eth0 preferred_lft 0


... then omit the auto eth0:0 and iface eth0:0 stuff entirely.

Alternatively, leave the "gateway" off of the eth0:0 stanza. All other things being equal, the kernel will pick the most recently added default route, and that would be the last one...
Back to top  
iWizardPro



Joined: 15 Jun 2011
Posts: 19

Posted: Tue Dec 27, 2011 11:47 pm    Post subject:  

I tried the way you specified "up /sbin/ip ..." and that didn't work. But, removing the gateway from the eth0:0 stanza worked. Thanks for your help! :D
Back to top  
 
       Linode Forum Index -> Linux Networking
Page 1 of 1