Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was looking at bringing up an interface like this in /etc/network/interfaces (this is on debian), with the gateway outside the subnet:

iface eth0 inet static
address 10.100.10.99
netmask 255.255.255.0
gateway 10.100.0.1

but "ifup --verbose eth0" only gives me this error message:

ifconfig eth0 10.100.10.99 netmask 255.255.255.0
 route add default gw 10.100.0.1  eth0
SIOCADDRT: No such process
Failed to bring up eth0

Of course, changing the netmask to 255.255.0.0 works just fine.

Is that even possible, or is there something else that's the problem? Is there a way to get more information out of ifup? I see one post on the internet that suggests it should work.

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Another way of approaching this question is: if you can't reach the your default-gateway router on a local network, how do you send packets through it? You'd have to send them through another router.

For some background, remember that an IP packet typically contains the source and destination addresses: where it comes from, and where it wants to go. It's usually up to the routers to decide how it gets there.

So when you send your IP packet through your off-network default gateway router, one of two things would need to happen.

  1. The local-network router knows how to reach the default-gateway router, and it agrees with your idea that your packet should be sent through the default-gateway router to get to its destination. In that case, why not just use the local-network router as your default gateway?

  2. The local-network router thinks (by default) that your packet should be sent through some other router to get to its destination. In this case you have to have some way to tell it otherwise. This capability exists, and is called "source routing"... but it is considered a security risk, and most routers are configured to ignore it.

Finally, in my experience, the Linux iproute (ip) tool will not let you add a route if the gateway cannot be reached directly via a local network interface.

A couple of source-routing references:

share|improve this answer
add comment

The default gateway has to be on the same subnet as the IP address of the device. It's typically the router's IP address of the network that you're connecting to. From the wikipedia page on Default Route:

In computer networking, a gateway is a node (a router) on a TCP/IP network that serves as an access point to another network. A default gateway is the node on the computer network that the network software uses when an IP address does not match any other routes in the routing table. It is actually the IP address of the router to which your PC network is connected.

In home computing configurations, an ISP often provides a physical device which both connects local hardware to the Internet and serves as a gateway. Such devices include DSL routers and cable routers.

In organizational systems a gateway is a node that routes the traffic from a workstation to another network segment. The default gateway commonly connects the internal networks and the outside network (Internet). In such a situation, the gateway node could also act as a proxy server and a firewall. The gateway is also associated with both a router, which uses headers and forwarding tables to determine where packets are sent, and a switch, which provides the actual path for the packet in and out of the gateway.

In other words, a default gateway provides an entry point and an exit point in a network.

share|improve this answer
    
But if there is a static route to an address, couldn't that be the default gateway even if it isn't on the subnet? (We're getting into technicalities here and away from good practice). –  kurtm Oct 31 '13 at 19:25
    
The static route can be a route, just not the default gateway (as I understand it). –  slm Oct 31 '13 at 19:34
2  
The default route MUST be on the same subnet. The Default route is how you get all your traffic off your subnet and onto another. So from if your trying to get traffic from 10.100.10.99 to 10.100.0.1 you need a "gateway" to get from the 10.100.10.0/24 to 10.100.0.0/24 networks. 10.100.0.1 can not be your default gateway because you can't reach it by default. It can however be "a" gateway. And it can even be "the" gateway you send all of your traffic to (once you tell it how to get to the other network). –  coteyr Oct 31 '13 at 21:24
add comment

It is possible, but as explained in the linked article your machine must already know how to get to the gateway address. This means that you will need to use post-up to manually add the routes instead of gateway

iface eth0 inet static
  address 10.100.10.99
  netmask 255.255.255.0
  post-up ip route 10.100.0.0/24 via 10.100.10.x # router that can route you to the 10.100.0.0/24 network
  post-up ip route 0.0.0.0 via 10.100.0.1
share|improve this answer
1  
These ip route commands will fail if you try them... even if you add the missing add command. –  Jander Oct 31 '13 at 22:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.