2

I need to run the command

route add -p 123.45.67.8 mask 255.255.255.0 208.00.000.000

on a linux server. what is the unix equivalent?

1
  • 2
    route --help or man route would have displayed help to answer this.
    – Hannu
    Jun 9, 2015 at 17:43

4 Answers 4

2

They are very similar.

To add a route for a network – in this example, 192.168.20.0 mask 255.255.255.0

sudo route add -net 192.168.20.0/24 gw 10.0.0.1

or

sudo route add -net 192.168.20.0 netmask 255.255.255.0 gw 10.0.0.1

To add a route for a host

sudo route add -host 192.168.20.20 gw 10.0.0.1

If you run route add with no options it will give you the list of options that you can use. e.g., metrics, interface, and some others.

Also the man page will help.

1
  • ip route is the more modern tool, so I'd be inclined to recommend that over route. I suspect we'll gradually see less of the latter over time. Jun 9, 2015 at 18:06
0

Without an explanation of what that Windows command does, it's hard to answer, but it looks like you should read the manual page for ip-route.

3
  • I need to run the command on a linux server. No windows involved.
    – Hennes
    Jun 9, 2015 at 17:41
  • Yes, but for a Linux user like myself, just presenting a Windows command with no explanation isn't very meaningful. Jun 9, 2015 at 18:05
  • True. It looked like a linix command to me though, so I guess it is all up to experience with older commands (I mainly used Linux in the time there was no ip command yet and the 1.2.8 kernal was the stable one ) And I also needed to read the question twice to check no windows was involved.
    – Hennes
    Jun 9, 2015 at 22:52
0

One way to make the route be persistent is to add it every time the machine is started. This has same result as -p flag on Windows.

This can be done using Cron:

@reboot /sbin/route add -net 123.45.67.8 netmask 255.255.255.0 gw 208.0.0.0 

dev eth0 can be used at the end of command if there is need to specify port to be used.

This works at least on Ubuntu 14.04 and probably on most modern implimentations of Cron.

1
  • Alternative to using a crontab entry is to specify it in /etc/network/interfaces (for Debian, I'm not sure which other distributions have it in the same place). I'll write a short answer for that. Jun 10, 2015 at 8:22
0

To add the route every time the interface is brought up, and remove it every time it goes down, a suitable command can be added to the interface's stanza in /etc/network/interfaces (for Debian). Here's one of mine (this makes local broadcasts go to the local network rather than to the ISP on my NAT gateway):

iface eth1 inet static
      address 192.168.0.2
      netmask 255.255.255.0
      pre-up iptables-restore </etc/iptables.rules
      up route add 255.255.255.255 eth1
      down route del 255.255.255.255

This can be easily adapted to your OS and needs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .