Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, I'm new to Linux and was looking to setup a custom routing for a specific network. In windows, I used to type this command: "route –p add 192.168.1.0 mask ...
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    9

    Question help with "route" command on CentOS

    Hello,

    I'm new to Linux and was looking to setup a custom routing
    for a specific network.

    In windows, I used to type this command:

    "route –p add 192.168.1.0 mask 255.255.255.0 192.168.2.50"

    which does set the PC (which belongs to 192.168.2.0 network)
    to remember this route even on reboots, and tells it to route all
    packages for network 192.168.1.0 via the gateway 192.168.2.50
    which is my VPN crossing bridge to the other network...


    Can anyone help me how I can do the same in Linux / CentOS?
    Last edited by mzraptor; 09-11-2011 at 10:59 AM.

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    I assume, that the device with the IP 192.168.2.x is eth0.

    For a reboot safe config, create/edit /etc/sysconfig/network-scripts/route-eth0 with the following content:
    Code:
    192.168.1.0/24 via 192.168.2.50 dev eth0
    To create the route adhoc, use this
    Code:
    route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.2.50 dev eth0
    You must always face the curtain with a bow.

  3. #3
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    For additional informations, look here:
    14.4.*Configuring Static Routes
    You must always face the curtain with a bow.

  4. #4
    Just Joined!
    Join Date
    Sep 2011
    Posts
    9
    Quote Originally Posted by Irithori View Post
    I assume, that the device with the IP 192.168.2.x is eth0.

    For a reboot safe config, create/edit /etc/sysconfig/network-scripts/route-eth0 with the following content:
    Code:
    192.168.1.0/24 via 192.168.2.50 dev eth0
    To create the route adhoc, use this
    Code:
    route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.2.50 dev eth0


    Thank you lrithori, it worked great!

  5. #5
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    You can do this with iproute2's "ip" command from the commandline as well if you do not need the route to persist between reboots:

    ip route add 192.168.1.0/24 via 192.168.2.50 dev eth0

    If you need to change the route, you could do:

    ip route replace 192.168.1.0/24 via 192.168.222.50 dev eth0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...