1

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.

4
  • Can you describe your network layout in further detail? Does each interface have an attached router that you want to forward packages to?
    – vidarlo
    Jun 29 at 15:40
  • why not using basic ip route?
    – djdomi
    Jun 29 at 20:03
  • thanks @djdomi. Seems ip route is what i need. Now i just need to find out what the correct routes look like.
    – danba
    Jul 1 at 6:22
  • @danba since oyu did not tell what is exactly the issue, i cant help currently (X and Y Problem)
    – djdomi
    Jul 1 at 11:34
2

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.

3
  • @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
    – djdomi
    Jul 5 at 4:23
  • 1
    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.
    – danba
    Jul 5 at 5:58
  • Okay, one point for you i forget the flush default :)
    – djdomi
    Jul 5 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.