Does a Gateway of a Subnet need to be a "real" Computer?

Solution 1:

Default route (aka gateway address) has to be owned by something that is capable of forwarding packets to the rest of the internet, and which is willing to do so. It doesn't have to be the "principal" IP address of the thing that owns it (whatever that means). It can be a logical address that floats between two or more devices, and in high-availability setups it often is.

The only requirement, in order that routing works, is that whatever device currently owns and advertises the address, that device can and will route traffic.

Solution 2:

The IP address of the gateway can be any valid host IP address in the subnet, i.e. not the network address itself nor the broadcast address. This IP address does not need to belong to a single computer or router, it can be a "floating" IP address used by several gateways. Check out the Wikipedia articles on HSRP, VRRP, GLBP, or CARP.

For example, when the subnet is 172.16.23.0/25, then:

  • the network address is 172.16.23.0,
  • the broadcast address is 172.16.23.127, and
  • the range of valid host addresses is from 172.16.23.1 till 172.16.23.126, inclusive.

The gateway must be any of these valid host addresses, e.g. 172.16.23.65. The settings of your computer would then be, e.g.:

  • IP address: 172.16.23.5
  • Subnet mask: 255.255.255.128
  • Default gateway: 172.16.23.65

Now adding in one of the first-hop redundancy protocols, the actual gateways (routers) can have the IP address 172.16.23.1 and 172.16.23.2 but use the virtual IP address of 172.16.23.65 to present themselves as the default gateway to the subnet.


Solution 3:

"Logical entity" in your usage is a tiny bit confusing. But I'll try to answer it best I can.

From my experience, a gateway in an IP configuration is usually a physical device. While it doesn't have to be a computer in the traditional sense (it can also be a network appliance) it does have to be device.

As you may know, the purpose that a default gateway serves is to act as a forwarding entity for all requests that a.) the computer doesn't already have in its routing table or has an entry instructing the system to forward the request to an IP that happens to be the gateway and/or b.) that are outside of the broadcast domain. The default gateway is never used in situations where two hosts are on the same broadcast domain (i.e. a network topology created by a switch) because the system can use the subnet's broadcast address to find the MAC address of a system owning a particular IP address.

In short, to answer your question, technically, you can set your default gateway as any IP address on a connected network. Windows or most other OSs for that matter won't stop you because they often don't perform verification of TCP/IP details. If you're setting it, you're most likely technically-savvy enough to understand the distinction. However, if it is the IP address of a device that is unable to forward, then it will result in errors in applications reliant on routing (i.e. a web browser) because the device won't be prepared with a routing table or a routing service to forward the request.

Someone much more experienced than myself, however, should be able to easily correct me if I am wrong.

TL;DR - A physical device, most likely.


Solution 4:

Routing table entries resolve a subnet to either a gateway or a network adapter.

A typical routing table for a device on a private network might, if you leave out the unnecessary stuff, look like

0.0.0.0/0 via 192.168.0.1
192.168.0.0/24 dev eth0

The most specific route wins for each destination, so the subnet route takes precedence over the default route for addresses in the subnet.

The gateway address is, in turn, resolved through the routing table, which determines the network interface it is given to as well as addressing on the lower layer.

So, for a packet to 1.1.1.1, the destination is looked up in the routing table, returning the default route, which has a gateway. The gateway is looked up again, returning the Ethernet interface.

Ethernet has MAC addresses, so an ARP lookup is done for the gateway address, and the MAC address for the gateway is used for the outgoing packet (which still uses the proper destination address in its IP header).

Other lower-level transports work differently, for example PPP links have a "peer address", so their device route uses a netmask of /32, and they skip ARP resolution and just send packets as "broadcast" over the PPP link.

Some IP stacks require manual creation of the device route, which makes this a bit more obvious:

ifconfig eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255 up
route add -net 192.168.0.0 netmask 255.255.255.0 dev eth0
route add default via 192.168.0.1

Tags:

Subnet

Gateway