LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   unable to add default route (network unreachable) (https://www.linuxquestions.org/questions/linux-networking-3/unable-to-add-default-route-network-unreachable-326465/)

beebop 05-23-2005 11:24 PM

unable to add default route (network unreachable)
 
I am trying to connect my laptop to the ethernet at work. However, I cannot ping the router from my laptop, even though I am using the same cable as my work's desktop (I'm unplugging from the desktop and plugging in my laptop).

Booting into my freshly installed Fedora Core 3 partition doesn't work. I ran this

ifconfig eth0 192.168.0.71 netmask 255.255.255.224
ping 192.168.0.1

and no pings went through. Pinging 192.168.0.71 works fine though, so I know eth0 is working... And yes, the cable is connected :) Booting into windows on my laptop connects to the 'net just fine using the same cable. I just had to use the same static IP, gateway, and netmask as the desktop.

So I though the routing table might be off. Here's what `/sbin/route` shows:

Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.71 * 255.255.255.224 U 0 0 0 eth0

I thought, "why isn't there a default gateway?" so I typed `/sbin/route add default gw 192.168.0.1` which resulted in:

STOCADDRT: Network is unreachable

Any ideas?

mrcheeks 05-23-2005 11:33 PM

why wouldn't be the netmask 255.255.255.0?

fr_laz 05-24-2005 04:45 AM

Hi,

By using 255.255.255.224 mask, this makes 32 hosts (well 30 if you count with network & broadcast addresses) in your network. Beeing the .71 host, your network ranges from 192.168.0.64 (network address) to 192.168.0.95 (broadcast address).
Thus 192.168.0.1 is not in your subnet. If it also has the samemask, it's subnet starts at 192.168.0.0 (network address) and ends at 192.168.0.31 (broadcast address).
So if you didn't mistake yourself with the mask, then you _have_ to choose an IP between 192.168.0.2 and 192.168.0.30.

If you can change the mask to 255.255.255.0 on _every_ machine of your LAN, I'll really advise you to do so, since it's much more simple to manage (with a .0 mask, network range is from .0 to .255 which is more common)

beebop 05-24-2005 08:11 AM

Well, the thing is, I am not the sysadmin of my workplace. But I believe he set up the netmask like that so he could make a sub-subnet with our alotted IPs. We only have about 10 computers, some for clients to use for browsing the net and checking email, and some more restrictive ones for accounting and stuff. I'm trying to connect to the "email" computer subnet.

But why would my windows partition connect? It uses the exact same numbers. 192.168.0.71, 255.255.255.224, and 192.168.0.1 for the gateway. It makes sense that it wouldn't be able to see the 192.168.0.1 because of the mask, so maybe there's some link before the internet gateway. Yeah, I bet I'm trying to make 2 hops, which requires some addition to the routing table in my laptop. Does Windows create the correct routing table automatically or something?

I'm trying to get ahold of the sysadmin, but he's busy with other companies, too. In the meantime, I'll keep plugging away with LQ's help :) I love this site!

fr_laz 05-24-2005 08:18 AM

Re,

it's possible that the Win PC got a route to 192.168.0.0 either configured 'in hard' or through dhcp. You can check it out with the 'route print' command in a DOS terminal.

beebop 05-24-2005 05:02 PM

Below is a printout from my windows partition on my laptop while connected to the ethernet cable at work. After rebooting into linux and running

route add 0.0.0.0 netmask 0.0.0.0 gw 192.168.0.1

I got the same 'network unreachable' error as before. I don't get why windows can get away with adding the default. Well, hopefully this printout will help answer some questions:

C:\Documents and Settings\becker>route print
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 a0 cc c3 70 86 ...... SiS 900 PCI Fast Ethernet Adapter - Packet Sched
uler Miniport
===========================================================================
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.71 20
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.0.64 255.255.255.224 192.168.0.71 192.168.0.71 20
192.168.0.71 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.0.255 255.255.255.255 192.168.0.71 192.168.0.71 20
224.0.0.0 240.0.0.0 192.168.0.71 192.168.0.71 20
255.255.255.255 255.255.255.255 192.168.0.71 192.168.0.71 1
Default Gateway: 192.168.0.1
===========================================================================
Persistent Routes:
None

C:\Documents and Settings\becker>

mrcheeks 05-25-2005 03:29 PM

could it be because you didn't put any nameserver in /etc/resolv.conf?

fr_laz 05-26-2005 05:04 AM

Hi,

I don't think it's linked to dns, since the route he tries to add doesn't contains references to names, only IPs.

this one route is queer :
192.168.0.255 255.255.255.255 192.168.0.71 192.168.0.71 20

it says : if you want to talk to 192.168.0.255, then do it right through your ethernet interface, there's no router in-between... why not, but that's a broadcast address... I don't think there's an host with this IP !

Maybe you could try to add this route in your Linux box and then add the default gw. I don't see why it would work, but that's the only thing that's not classical in your windows routing table (and you do have a routing issue, since your gateway is not in the same subnet as your Linux box).

scowles 05-26-2005 07:14 AM

I guess Microsoft's tcp/ip stack compensates for specifying a gateway address outside the host address range for the subnet.

Just for grins, I tried configuring my XP box with the same netmask and... whoa! it worked.
Code:

===========================================================================
Active Routes:
Network Destination        Netmask          Gateway      Interface  Metric
          0.0.0.0          0.0.0.0      192.168.9.1    192.168.9.71      1
        127.0.0.0        255.0.0.0        127.0.0.1      127.0.0.1      1
    192.168.9.64  255.255.255.224    192.168.9.71    192.168.9.71      1
    192.168.9.71  255.255.255.255        127.0.0.1      127.0.0.1      1
    192.168.9.255  255.255.255.255    192.168.9.71    192.168.9.71      1
        224.0.0.0        240.0.0.0    192.168.9.71    192.168.9.71      1
  255.255.255.255  255.255.255.255    192.168.9.71    192.168.9.71      1
Default Gateway:      192.168.9.1
===========================================================================

C:\>ping 192.168.9.1

Pinging 192.168.9.1 with 32 bytes of data:

Reply from 192.168.9.1: bytes=32 time<1ms TTL=64
Reply from 192.168.9.1: bytes=32 time<1ms TTL=64
Reply from 192.168.9.1: bytes=32 time<1ms TTL=64
Reply from 192.168.9.1: bytes=32 time<1ms TTL=64

C:\>ping www.yahoo.com

Pinging www.yahoo.akadns.net [68.142.197.83] with 32 bytes of data:

Reply from 68.142.197.83: bytes=32 time=27ms TTL=58
Reply from 68.142.197.83: bytes=32 time=25ms TTL=58
Reply from 68.142.197.83: bytes=32 time=25ms TTL=58
Reply from 68.142.197.83: bytes=32 time=25ms TTL=58

Incredible! In a perfect world, the above should NOT work. But then look at the classful broadcast address that the MS stack calculated. Again, in a perfect world (well classless at least), the broadcast address should be 192.168.9.95

To the OP - the problem description and solution that fr_laz posted is correct. Until you change your netmask to 255.255.255.0, the linux tcp/ip stack is NOT going to allow you to add a defualt route which is outside the host address range for the network address. Why the Micosoft stack does is anyones guess. You would think Microsoft would perform some sort of sanity check when you hit the OK button. <groan!>

beebop 05-26-2005 02:22 PM

Hey guys, thanks for all your help. It's working fine now. I figured, "If my router (192.168.0.1) is outside my subnet (255.255.255.224), why not change my subnet to include it? So on my laptop I ran

ifconfig eth0 192.168.0.71 subnet 255.255.255.0 <--- note the changed subnet

and it worked just fine. I'm still confused as to why the the sysadmin configured the subnet with the 224, but oh well. My laptop works now and that's all that matters.

--Beebop

scowles 05-27-2005 05:48 AM

Glad you are up and running

For future reference - most, if not all linux distro's include a command called "ipcalc" (which I should have used before I posted my previous reply. I incorrectly stated the broadcast address). Anyway, given an IP/netmask combination...
Code:

[root@excelsior sysconfig]# ipcalc --network 192.168.0.71 255.255.255.224     
NETWORK=192.168.0.64
[root@excelsior sysconfig]# ipcalc --broadcast 192.168.0.71 255.255.255.224   
BROADCAST=192.168.0.95

...the host addressable range (including the default route) should fall between the two. The default route is "usually" the lower or upper end of the host address range. i.e.
Code:

NETWORK=192.168.0.64
HOST_ADDRESS_1=192.168.0.65  <- typical default route
.... PC/Server addresses
HOST_ADDRESS_30=192.168.0.94  <- typical default route
BROADCAST=192.168.0.95


fr_laz 05-30-2005 04:49 AM

Hi,

for info there's also a perl version of ipcalc, which can be usefull when scripting...

charon79m 05-30-2005 11:07 AM

I've set-up networks like this previously. The reason I did it was to provide an incorrect default gw to disallow internet acccess to users that should not have Internet connection. On these networks, we used a proxy server for internet access and there was no "Default Gateway" that allowed for direct internet access.

It was simply a way of confusing those who did not know how our network worked. Those who tired to figure it out were quickly detected by our IDS and dealt with.

In all, it was an effective method of controlling the network.

MrKnisely


All times are GMT -5. The time now is 06:17 PM.