Score:1

Assign each NIC an ip range or subnet

in flag

I have a manjaro linux server with at least two network interface controllers (NICs) and would like to route all traffic going to certain IP address ranges or subnets over one, and everything else over one of the others.

So far I've configured the networks via nmcli, but I only have a tenuous grasp of the subject.

Ideally the solution would work via the command line, be persistent and not depend strongly on the distribution used.

Edit: As per Route IP Traffic using nmcli / Centos 7 something along the lines of

nmcli connection modify "Wired connection 1" +ipv4.routes "10.0.0.0/16"

should work, however the packages don't seem to be routed across the correct network.

vidarlo avatar
ar flag
Can you describe your network layout in further detail? Does each interface have an attached router that you want to forward packages to?
djdomi avatar
za flag
why not using basic `ip route`?
in flag
thanks @djdomi. Seems ip route is what i need. Now i just need to find out what the correct routes look like.
djdomi avatar
za flag
@danba since oyu did not tell what is exactly the issue, i cant help currently (X and Y Problem)
Score:2
za flag

General Pre-Information about this Answer

I assume my Answers in Generally on my Knowledge based on Debian Systems, however in this part I skip the Network-Manager Part due I am not using it anyway and in my personal mind makes it only complicated.

You Asked, and in the Comments it seems to be nearly clear, that you want to route the 10.0.0.0/16 to another network card.

You Provided "Wired connection 1" +ipv4.routes "10.0.0.0/16"

-- which device name should the right one, can be found out via ip address or ifconfig -- Usually you unsure to it, unplug the cards cable and look to dmesg or /var/log/syslog

So in My Example, assume the Following:

  • "Wired connection 1" = eth0
  • "10.0.0.0/16" or 10.0.0.0/255.255.0.0 (or 10.0.0.0-10.0.255.255) should be routed to eth0

The Short way for testing or pre-set, not Persistent:

ip route add 10.0.0.0/16 dev eth0

The Tricky Part for now is, getting it Persistent.

On RHEL/CentOS/Fedora/Scientific based Systems,

  • edit /etc/sysconfig/network-scripts/route-eth0

Adding here

 10.0.0.0/16 via 10.0.0.1

Where the First is the Network you want to match, second the IP of the Router. In My example, 10.0.0.1

Using the Debian Way. (Debian Bases Systems, Like Ubuntu)

on some Systems, /etc/network/interfaces may seem to be empty. In that case, you have to look into vi /etc/network/interfaces.d, but we assume the basic /etc/network/interfaces file to be used.

  • edit /etc/network/interfaces

Look for your Interface eth0

iface eth0 inet static
        address  10.0.0.2
        netmask  255.0.0.0

Modify, that it looks like

iface eth0 inet static
        address  10.0.0.2
        netmask  255.0.0.0
###EITHER with Gateway
#post-up route add -net 10.0.0.0 netmask 255.255.0.0 gw 10.0.0.1 dev eth0
#post-down route del -net 10.0.0.0 netmask 255.255.0.0 gw 10.0.0.1 dev eth0

###or without Gateway
#post-up route add -net 10.0.0.0 netmask 255.255.0.0 dev eth0
#post-down route del -net 10.0.0.0 netmask 255.255.0.0 dev eth0

The Generic, Static Way (Might be outdated on Systemd enabled systems)

Edit /etc/rc.d/rc.local or /etc/rc.local

add

  • ip route add 10.0.0.0/16 dev eth0

This answer is meaned to solve it in generally.

djdomi avatar
za flag
@danba it would be great if you could accept the answer if it helped you, or tell me in case if not so i can ajust my answer
in flag
thanks for the detailed answer. I ended up having to specify the via for the route in order to get any packets to go over it. `ip route add 10.0.0.0/8 via 10.39.0.1 dev eth0`. Also i realized that i had multiple default routes (one for each device), and I only wanted one device to be used as a fallback in case there's no more specific route, so i removed the excess defaults by `ip route flush default via 10.39.0.1 dev eth0`.
djdomi avatar
za flag
Okay, one point for you i forget the flush default :)
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.