# IP and Gateway on different subnets!

## kedadi

hi everybody,

I'm having troubles on setting up the network on my gentoo, my ISP gave me a public ip address but the gateway is on another subnet:

```

#ifconfig eth0 38.102.47.148 netmask 255.255.255.240 up

#route add default gw 38.102.193.217

SIOCADDRT: Network is unreachable

```

I also tried to config /etc/conf.d/net manually but still couldn't make it work, basically it should not work I guess, becasue of different subnets, but using the same ip address and the same gateway another machine running win32 works great, so does anybody have any idea how to achieve this also in gentoo or to force the kernel to use that gateway on different subnet?

Regards

----------

## NeddySeagoon

kedadi,

As the kernel does not yet know how to reach the gateway your 

```
route add default gw 38.102.193.217 
```

needs to include the interface to be used too. Try 

```
route add default gw 38.102.193.217 dev eth0
```

----------

## kedadi

NeddySeagoon,

thanks for your reply,

I tried:

```

route add default gw 38.102.193.217 dev eth0

```

but I'm still geting the same error message from the kernel:

```

SIOCADDRT: Network is unreachable

```

do you know if the kernel can be forced to use a gateway from a different subnet?

Regards,

----------

## grosnours

You can't, as you need a gateway (aka router) to go on other networks. Try 38.102.47.145 as gateway address or better, check with your provider if you got the numbers right (your ip, netmask and the gateway ip).

----------

## kedadi

grosnours,

 *Quote:*   

> 
> 
> You can't, as you need a gateway (aka router) to go on other networks. Try 38.102.47.145 as gateway address or better, check with your provider if you got the numbers right (your ip, netmask and the gateway ip).
> 
> 

 

as I said, a machine running a win32 works using the same addressing (ip, gateway and the subnet mask).

Regards

----------

## think4urs11

 *kedadi wrote:*   

> as I said, a machine running a win32 works using the same addressing (ip, gateway and the subnet mask).

 

Check/compare the routing tables between Win and Gentoo then.

Might work with

```
ifconfig eth0 38.102.47.148 netmask 255.255.255.240 up

route add -net 38.102.0.0/16 dev eth0

route add default gw 38.102.193.217 dev eth0
```

----------

## NeddySeagoon

grosnours,

In this sense a gateway is not a router, or a switch. Its an IP address that packets need to be addressed to to reach other networks.

That is, your system does not know how to reach the other network(s) directly but it knows a machine that can.

It should just work.

There was another thread on this topic started on Friday 1st Dec too. There, the poster could not make the same setup work from /etc/conf.d/net.

----------

## kedadi

hi everybody,

thank you very much for your quick replies and for your time,  

I asked my ISP to put the gateway on the same subnet with my ip and they did it, so now everything is working,  

ps. I was a bit nervous with the fact that a machine running a crap OS just worked, some of my friends (win32 fanboys of course) started laughing with linux  :Sad: ,

anyways thank you very much of your time and replies,

Regards

----------

## damato

Hey guys. let me put in a cross link here to another article in the forum dealing with the very same problem but in terms of having a provider's DHCP server supplying a gateway which is located in another subnet.

https://forums.gentoo.org/viewtopic-p-3760517.html#3760517

It deals with the more or less exact issue and outlines that this is not only an issue for manually setting the default gateway to an IP which is not part of a currently known subnet.

----------

