Changing gateway helps to connect to internet, but why?

image

While changing gateway, it helps me connect to internet in VM in a bridged adapter virtualbox vm.
But when I keep the gateway as 192.168.1.1 it doesn't work.

For context, the VM's IP when bridged is 192.168.1.10 whereas the subnet mask is /24. I used jodies calculator to calculate the network address etc. And as far as I know, the gateway address is the first host ip+1. Am I wrong here?

Remember 192.168.1.254 is the ip of my router at home.

The netmask of /24 means that 192.168.1.0 is a network (segment) address, thus the first "usable" host IP address in such a network can be 192.168.1.1 (exactly network address + 1 = 192.168.1.0 + 1), the last usable (possible to assign to a device) is 192.168.1.254 (as 192.168.1.255 is the network "broadcast" address).
Also, gateway is not just an arbitrary (any) IP address in network segment, it usually is a single, specific IP address (not necessarily the first), that is assigned to router's LAN interface of your network (regardless it's virutal or physical). Make sure you understand the basics of IPv4 networking, and that you know the "layout" (infrastructure/all available devices and their IP addresses) inside your network.

3 Likes

A gateway and a router are, for most common purposes, the same thing. Essentially, a gateway is a server or appliance that knows how to get from one network to another. And the default gateway is the router that your host will talk to to find out how to get to any other sub-net that it doesn't have a specific route to. In other words, for most people the default gateway is how you connect a host up to the Internet.

In terms of its own IP address configuration, a gateway can have any IP on the sub-nets to which it is connected - there is no rule that you can use to work out what the gateway IP is for a given sub-net, as whoever configured the gateway could have given it any IP on that sub-net.

The most typically-used convention for gateway addresses is to assign the last usable IP in a sub-net to the gateway (so the address before the broadcast address), but that's purely a convention - you can give a router any IP you like. Unlike the network number or broadcast address, which are indeed fixed and determined by the netmask, a gateway's IP can be anything that's not already used by another host.

But if you want to communicate between sub-nets (or from a local area network to the wider Internet), your hosts's default gateway will need to be the IP of your router/gateway.

Hope this helps !

1 Like