LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to set up persistent routes between 192.168.2.XXX and 192.168.0.XXX (https://www.linuxquestions.org/questions/linux-networking-3/how-to-set-up-persistent-routes-between-192-168-2-xxx-and-192-168-0-xxx-4175426385/)

cgeekwannabe 09-09-2012 12:33 PM

How to set up persistent routes between 192.168.2.XXX and 192.168.0.XXX
 
My Fedora Core 17 sits on the 192.168.2 subnet and the rest of my network sits on the 192.168.0 subnet. I'm wondering if there's a way to set up a static route between FC and say..192.168.0.191

Computers on the 192.168.0 subnet can talk to (i.e. scp) to 192.168.2 but not the other way around. I was told that a route would fix it and I know how to set them up I'm just not sure what I should put in the entries

Here's my ifcfg-eth0 on FC17

UUID="d09fea4f-b616-4815-afa4-30bb073cecc6"
NM_CONTROLLED="yes"
HWADDR="00:1C:25:EA:16:76"
BOOTPROTO="static"
DEVICE="eth0"
ONBOOT="yes"
IPADDR=192.168.2.12
NETMASK=255.255.255.0
GATEWAY=192.168.2.1

And here's the corresponding file on Debian - yes I know it's still DHCP but I don't think things will change once I get the routes on FC17 since Debian can see FC. Besides, I can convert it to static pretty easy.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

output from route command on debian

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 * 255.255.255.0 U 2 0 0 wlan0
link-local * 255.255.0.0 U 0 0 0 eth0
default 192.168.0.1 0.0.0.0 UG 0 0 0 wlan0
default * 0.0.0.0 U 1002 0 0 eth0


output from route command on fc17

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0

kbp 09-09-2012 06:43 PM

To add a static route on Fedora you create a file based on the interface used to reach the remote network

Code:

cat <<EOF> /etc/sysconfig/network-scripts/route-eth0
# Dev subnet
GATEWAY0=192.168.1.10
NETMASK0=255.255.255.0
ADDRESS0=10.0.0.0
# Test subnet
GATEWAY1=192.168.1.20
NETMASK1=255.255.255.0
ADDRESS1=10.1.1.0
EOF

Each route requires a set of three options (gateway, netmask and address) and they're numbered to differentiate them from each other.

cgeekwannabe 09-09-2012 07:03 PM

What do ADDRESS0 and ADDRESS1 represent?

kbp 09-09-2012 07:11 PM

Two different networks, I added 2 to make the naming/numbering obvious

cgeekwannabe 09-09-2012 11:38 PM

Sorry to be so thick but now I'm kinda confused.
Are you saying that in order for my Fedora Core box with

IPADDR=192.168.2.12
NETMASK=255.255.255.0
GATEWAY=192.168.2.1

to reach computers with

GATEWAY=192.168.0.1

I need to have two *entries* in my routes file? Or do I only need one route for the entire 192.168.0.1 subnet?
Something like this:

# Dev subnet
GATEWAY0=192.168.0.1 <-- this is the gateway of the subnet I want to reach
NETMASK0=255.255.255.0
ADDRESS0=192.168.2.12 <--- this is the IP of the FC box
EOF

kbp 09-10-2012 12:06 AM

Ok .. let's slow this down, to communicate outside the network you are attached to you need a gateway. Your default gateway is a host on the same network as you to which your computer will send any traffic that isn't on the same network. A gateway is defined by the fact that it has interfaces on more than one network and it forwards traffic between them.

Local communication example (traffic is sent direct to the destination):
Code:

[PC:192.168.0.50] -> [Printer:192.168.0.5]
External communication example (traffic is sent to default gateway to handle):
Code:

[PC:192.168.0.50] -> [DGW:192.168.0.1] -> [anywhere else:111:222:333:444]
The only time you need a static route is if to get to the destination you *can't* go via your default gateway. In this case, the gateway (not default) that you use, still needs to be attached to your local network:
Code:

[PC:192.168.0.50] -> [GW:192.168.0.2] -> [somewhere else:10.0.0.1]
So the entry in your route-eth0 file should be:
Code:

GATEWAY0=192.168.2.?      <-- this is address of the gateway's interface on *your* network
NETMASK0=255.255.255.0    <-- subnet mask for the destination host's network
ADDRESS0=192.168.0.0      <-- network address (not host address) for the destination host

You can also make the route specific for one host like this:
Code:

GATEWAY0=192.168.2.?      <-- this is address of the gateway's interface on *your* network
NETMASK0=255.255.255.255  <-- subnet mask for a specific host
ADDRESS0=192.168.0.1      <-- ip address for the destination host


cgeekwannabe 09-10-2012 05:20 AM

Ok, I think I've got some of this sorted

The IP address of the wireless router that serves the 192.168.0.XXX subnet is 192.168.2.10 because it's hardwired into the same
modem that serves the 192.168.2.XXX subnet so that would be the GATEWAY0 entry. And ADDRESS0 would be 192.168.0.1 because that's the (in terms of your nomenclature) the network address (not host address) for the destination host. IIRC I would have put 192.168.0.1 in as the GATEWAY entry in the /etc/sysconfig/network-scripts/ifcfg-eth0 file.

Am I close?

kbp 09-10-2012 07:16 AM

Almost, 192.168.0.1 would be a host address not a network address, on a class c network (most likely) the network would be 192.168.0.0 and the subnet mask would be 255.255.255.0

So you can use:
Code:

GATEWAY0=192.168.2.10
NETMASK0=255.255.255.255
ADDRESS0=192.168.0.1

Or:
Code:

GATEWAY0=192.168.2.10
NETMASK0=255.255.255.0
ADDRESS0=192.168.0.0

.. depending on whether there are any other hosts on the 192.168.0.0 network that you want to communicate with.

cgeekwannabe 09-10-2012 10:05 AM

Ok.. I'll give that a try when I get home. I'll update the thread with my results.

Thanks

cgeekwannabe 09-10-2012 05:18 PM

Ok, here's what I have in my /etc/sysconfig/network-scripts/route-eth0

GATEWAY0=192.168.2.10
NETMASK0=255.255.255.255
ADDRESS0=192.168.0.191

And when I run the route command I see static routes but it's still not working

[root@leonard etc]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
sheldon.cgeekwa 192.168.2.10 255.255.255.255 UGH 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0

This is probably not going to work based on my network configuration.
I have a modem connected to my high speed provider. That modem is serving the 192.168.2.XXX network
Then I have a wireless router hard wired into the modem and it's IP is 192.168.2.10
The 192.168.0.XXX network is being served out of that. Unless I'm missing something obvious here.

kbp 09-10-2012 08:04 PM

Don't forget that the other host will also need a route to your network/machine .. are you sure that your router and wireless access point don't support adding static routes?


All times are GMT -5. The time now is 08:37 PM.