Multiple public IPs with multiple vmbr

SvenNiehus

New Member
Sep 20, 2015
1
0
1
Hello,

I've got the following IP Addresses from my hoster (Server4You):

[TABLE="width: 500"]
[TR]
[TD][/TD]
[TD]IP[/TD]
[TD]Netmask[/TD]
[TD]Gateway[/TD]
[/TR]
[TR]
[TD]Main IP[/TD]
[TD]85.xxx.109.203[/TD]
[TD]255.255.255.0[/TD]
[TD]85.xxx.109.1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Additional IP[/TD]
[TD]85.xxx.154.15[/TD]
[TD]255.255.255.0[/TD]
[TD]85.xxx.154.1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]85.xxx.154.18[/TD]
[TD]255.255.255.0[/TD]
[TD]85.xxx.154.1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]85.xxx.154.21[/TD]
[TD]255.255.255.0[/TD]
[TD]85.xxx.154.1[/TD]
[/TR]
[/TABLE]



My current interfaces config:

Code:
auto lo
iface lo inet loopback


auto eth0
iface eth0 inet static
        address  85.xxx.109.203
        netmask  255.255.255.0
        gateway  85.xxx.109.1
        post-up iptables-restore < /etc/iptables.up.rules


auto eth0:1
iface eth0:1 inet static
        address  85.xxx.154.21
        netmask  255.255.255.0


auto eth0:2
iface eth0:2 inet static
        address  85.xxx.154.18
        netmask  255.255.255.0


auto vmbr0
iface vmbr0 inet static
        address  192.168.1.1
        netmask  255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up iptables -t nat -D POSTROUTING -s '192.168.1.0/24' -o eth0 -j MASQUERADE
        post-down iptables -t nat -D POSTROUTING -s '192.168.1.0/24' -o eth0 -j MASQUERADE


auto vmbr1
iface vmbr1 inet static
        address  192.168.2.1
        netmask  255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0
        post-up iptables -t nat -D POSTROUTING -s '192.168.2.0/24' -o eth0:1 -j MASQUERADE
        post-down iptables -t nat -D POSTROUTING -s '192.168.2.0/24' -o eth0:1 -j MASQUERADE


auto vmbr2
iface vmbr2 inet static
        address  192.168.3.1
        netmask  255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0
        post-up iptables -t nat -D POSTROUTING -s '192.168.3.0/24' -o eth0:2 -j MASQUERADE
        post-down iptables -t nat -D POSTROUTING -s '192.168.3.0/24' -o eth0:2 -j MASQUERADE


How do I route the vmbr1 / vmbr2 through eth0:1 / eth0:2?
 
It's a rather simple process of source routing, Google LARTC for full details.

You have to tell the kernel that some IP's must go thru other gateway, and with other source address than the default on interface.


FOR EACH IP ADDRESS OTHER THEN THE DEFAULT

ip rule add from 85.xxx.154.15 lookup 2
ip r a
85.xxx.154.15/24 dev eth0 proto kernel scope link src 85.xxx.154.15 table 2
ip r a default via
85.xxx.154.1 table 2


This translates into words as flows:
For any traffic from
85.xxx.154.15 don't use the default routing table, use routing table 2
Add a new route so we can speak to the gateway using source IP, in routing table 2
Add a default route in table 2