does the gateway have to be on the subnet?
Another way of approaching this question is: if you can't reach 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.
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?
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:
- http://tools.ietf.org/html/draft-reitzel-ipv4-source-routing-is-evil-00
- http://lwn.net/Articles/232781/
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.
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