G
G
George2016-04-13 21:04:52
ubuntu
George, 2016-04-13 21:04:52

How to route outgoing requests through a second IP on the server?

Good day.
There is a server on ubuntu, the server has two external IPs (1.1.1.1 and 2.2.2.2)
in /etc/network/interfaces like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 1.1.1.1
  netmask 255.255.255.0
  network 1.1.1.0
  broadcast 1.1.1.255
  gateway 1.1.1.254
  post-up /sbin/ifconfig eth0:1 2.2.2.2 netmask 255.255.255.0 broadcast 2.2.2.2
  post-down /sbin/ifconfig eth0:1 down

How to make outgoing requests to a certain resource (3.3.3.3) through the second IP?
Or am I asking garbage and for an external resource all requests will go in any case from the same gw ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neatsoft, 2016-04-14
@ignietferro

You need to add the appropriate route:
askubuntu.com/a/252699 It is
better to configure the second address not through post-up, but with a separate rule:

auto eth0
iface eth0 inet static
  address 1.1.1.1
  netmask 255.255.255.0
  gateway 1.1.1.254

auto eth0:1
iface eth0:1 inet static
  address 2.2.2.2
  netmask 255.255.255.0
  up ip route add 3.3.3.3 dev eth0 src 2.2.2.2 via 2.2.2.254 || true
  down ip route del 3.3.3.3 || true

wiki.debian.org/NetworkConfiguration#Legacy_method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question