I have a linux server that needs to get some routing. I'm fairly new at this and i don't find any clear source on google.

The setup should be simple:
All traffic to a server on ip should be sent over interface 3. All other interfaces don't matter at the moment.

Here you have the output for route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0   U     0      0        0 eth1   U     0      0        0 eth2   U     0      0        0 eth3   U     0      0        0 eth4     U     1002   0        0 eth0         UG    0      0        0 eth0
  • 1
    Are you using the old fashioned ifconfig and route command or the modern ip commands? (old ones would be something like route add -host GW eth3_ip)
    – Hennes
    Mar 29, 2013 at 13:48
  • i don't know, i guess the old ones, how can i check that?
    – Frederiek
    Mar 29, 2013 at 13:58

2 Answers 2



ip route add dev eth3

  • 4
    Just a note: to permanently keep this configuration make sure you add it to /etc/rc.local or your distro's equivalent. It won't persist between reboots.
    – LawrenceC
    Mar 29, 2013 at 16:32
  • 2
    I tried this same format for mapping an IP to the wlan0 on Ubuntu 14.04 and got RTNETLINK answers: Invalid argument I had to remove the /** from the IP so I ended up with: sudo ip route add dev wlan0 -- thought I'd mention that in case anyone else ran into this issue. Thank you for your answer ultrasawblade, it was helpful.
    – mason81
    Jul 10, 2015 at 14:54
  • 5
    Do not forget via <gateway_ip> if the target IP is not directly reachable!
    – calandoa
    Dec 4, 2017 at 15:00
  • How would I add another entry saying "use this interface for all other destination IPs"? Jul 29, 2020 at 12:51
  • 1
    Thanks! What would be the $ROUTER_IP? Jul 29, 2020 at 18:27

you might need "via" in the command:

ip route add via dev eth3

See this similar issue CentOS 7 custom routes with 2 NIC's

  • 1
    No, via specifically indicates that a gateway address follows. The output interface is a separate parameter from a gateway.
    – user1686
    Aug 12, 2021 at 13:25

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.