Score:0

How to set up 20 IP's from 2 different Subnets / 2 Gateways on 1 Interface? - Debian 10

us flag

I'm trying to figure out a way to get my networking.service to work properly, so networking service restarts work.

How do I setup those 20 IP'S with 2 different Gateways but only 1 NIC? With 2 NIC's I wouldn't have any problem, but is that possible on 1 NIC?

This is what I get when I try to restart it by using systemctl restart networking.service:

Feb 06 22:37:40 v4033 ifup[1276]: ifup: failed to bring up eth0:16
Feb 06 22:37:40 v4033 ifup[1276]: RTNETLINK answers: File exists
Feb 06 22:37:40 v4033 ifup[1276]: ifup: failed to bring up eth0:17
Feb 06 22:37:40 v4033 ifup[1276]: RTNETLINK answers: File exists
Feb 06 22:37:40 v4033 ifup[1276]: ifup: failed to bring up eth0:18
Feb 06 22:37:40 v4033 ifup[1276]: RTNETLINK answers: File exists
Feb 06 22:37:40 v4033 ifup[1276]: ifup: failed to bring up eth0:19
Feb 06 22:37:40 v4033 systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Feb 06 22:37:40 v4033 systemd[1]: networking.service: Failed with result 'exit-code'.
Feb 06 22:37:40 v4033 systemd[1]: Failed to start Raise network interfaces.

A explanation of the IPS:

45.XX.XX.XX are the first IP's from subnet 1 with Gateway 45.XX.XX.1
5.XX.XX.XX are the second IP's subnet 2 with Gateway 5.XX.XX.1

My /etc/network/interfaces looks like this:

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
    address 45.XX.XX.XX
    gateway 45.XX.XX.1
    netmask 255.255.255.0
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 8.8.8.8

auto eth0:1
iface eth0:1 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:2
iface eth0:2 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:3
iface eth0:3 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:4
iface eth0:4 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:5
iface eth0:5 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:6
iface eth0:6 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:7
iface eth0:7 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:8
iface eth0:8 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:9
iface eth0:9 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:10
iface eth0:10 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:11
iface eth0:11 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:12
iface eth0:12 inet static
address 45.XX.XX.XX
netmask 255.255.255.0

auto eth0:13
iface eth0:13 inet static
address 5.XX.XX.XX
netmask 255.255.255.0
post-up ip route add 5.XX.XX.0/24 dev eth0:13 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.1 dev eth0:13 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX9/32 table rt2

auto eth0:14
iface eth0:14 inet static
address 5.XX.XX.XX
netmask 255.255.255.0
post-up ip route add 5.XX.XX.0/24 dev eth0:14 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0:14 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX/32 table rt2


auto eth0:15
iface eth0:15 inet static
address 5.XX.XX.XX
netmask 255.255.255.0
post-up ip route add 5.XX.XX.0/24 dev eth0:15 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0:15 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX/32 table rt2

auto eth0:16
iface eth0:16 inet static
address 5.XX.XX.XX
netmask 255.255.255.0
post-up ip route add 5.XX.XX.0/24 dev eth0:16 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0:16 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX/32 table rt2

auto eth0:17
iface eth0:17 inet static
address 5.XX.XX.XX
netmask 255.255.255.0
post-up ip route add 5.XX.XX.0/24 dev eth0:17 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0:17 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX/32 table rt2

auto eth0:18
iface eth0:18 inet static
address 5.XX.XX.XX
netmask 255.255.255.0
post-up ip route add 5.XX.XX.0/24 dev eth0:18 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0:18 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX/32 table rt2

auto eth0:19
iface eth0:19 inet static
address 5.XX.XX.XX
netmask 255.255.255.0
post-up ip route add 5.XX.XX.0/24 dev eth0:19 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0:19 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX/32 table rt2

And I have a /etc/iproute2/rt_tables which looks like this:

#
# reserved values
#
255 local
254 main
253 default
0   unspec
#
# local
#
#1  inr.ruhep
1 rt2

Thanks in advance!

Massimo avatar
ng flag
If you have multiple IP addresses on the same subnet, this is quite straightforward. But if you want multiple IP addresses on different subnets with different gateways, this could be a problem. You should ask your provider *why* are you stuck in such a situation.
us flag
@Massimo so that means theres no way to figure this out unfortunately? Yea, with the same subnet it would be easy, or with 2 NIC'S. I can try contacting my server hoster and ask for the ip's in the same subnet or for another NIC.
us flag
My hoster added another NIC, it works now.
Score:0
us flag

I think the problem is that you are repeating

post-up ip route add 5.XX.XX.0/24 dev eth0:16 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0:16 table rt2
post-up ip rule add from 5.XX.XX.XX/32 table rt2
post-up ip rule add to 5.XX.XX.XX/32 table rt2

for all your alias interfaces. I think you should have this only once, without the alias identifier:

post-up ip route add 5.XX.XX.0/24 dev eth0 src 5.XX.XX.XX table rt2
post-up ip route add default via 5..XX.XX.XX.1 dev eth0 table rt2
post-up ip rule add from 5.XX.XX.XX/24 table rt2
post-up ip rule add to 5.XX.XX.XX/24 table rt2
us flag
I tried it. This unfortunately only works with 1 of the 5.XX.XX.XX IP'S. If I try to add any other (with and without the post-up lines) it will give me the same "error".
us flag
My hoster added another NIC, it works now. With a new network card I just have to use the post-up commands for eth1 and then all the alias (eth1:1, 1:2 etc) is just the address and netmask.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.