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:

# 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:

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

2 Replies

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:

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…

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

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct