DEV Community

Kervie Sazon
Kervie Sazon

Posted on

Networking Fundamentals - Part 3: Gateway & Routing

What is a Default Gateway?

A default gateway is the device your server uses to leave its local subnet.

Think of it like this:

Your server = your house.
Your subnet = your neighborhood.
The default gateway = the main road exit.

If traffic is going outside your subnet, it must go through the gateway.

Example:
Server:

IP: 10.0.1.10/24
Gateway: 10.0.1.1
Enter fullscreen mode Exit fullscreen mode

If you try to reach:

10.0.1.50  → Same subnet → Direct communication
10.0.2.20  → Different subnet → Goes to 10.0.1.1
Enter fullscreen mode Exit fullscreen mode

Without a gateway configured:

  • You cannot reach other networks
  • No internet
  • No cross-subnet communication

What is Routing?

Routing is the process of deciding.

"Where should this traffic go?"

Your server checks:

  1. Is the destination inside my subnet?
  2. Yes → Send directly
  3. No → Send to default gateway

The router then forwards traffic to the correct destination network.

Checking Routing in Linux

Command:

ip route
Enter fullscreen mode Exit fullscreen mode

Example Output:

default via 10.0.1.1 dev eth0
10.0.1.0/24 dev eth0 proto kernel scope link src 10.0.1.10
Enter fullscreen mode Exit fullscreen mode

How to read this:
first line: default via 10.0.1.1 dev eth0

  • "default" - Used for anything outside local subnet.
  • "via 10.0.1.1" Gateway IP.
  • "dev eth0" - Interface used.

second line: 10.0.1.0/24

  • This is your local subnet route.

Example Scenario
Problem:

"The server cannot access the internet."

Step 1
Check IP:

ip addr
Enter fullscreen mode Exit fullscreen mode

Step 2
Check routing:

ip route
Enter fullscreen mode Exit fullscreen mode

If you don’t see a default via line → No gateway configured.
That's the problem.

Things to Remember:

When troubleshooting, always ask:

  1. Do I have an IP?
  2. Am I in the correct subnet?
  3. Do I have a default gateway?
  4. Is the gateway reachable?

Examples for better understanding:

Example 1: Same Subnet (No Routing Needed)

Server A: 10.0.1.10/24
Server B: 10.0.1.20/24
Enter fullscreen mode Exit fullscreen mode

Step-by-step thinking:

  • /24 means first three numbers define the network
  • Both start with 10.0.1
  • So they are in the same subnet: 10.0.1.0/24

What happens?
Server A sends traffic directly to Server B.
No router involved.

Conclusion:

"The servers are in the same subnet and communicate directly. No routing or gateway configuration is required. Connectivity is confirmed."

Example 2: Different Subnet (Routing Needed)

Server A: 10.0.1.10/24
Server B: 10.0.2.20/24
Gateway: 10.0.1.1
Enter fullscreen mode Exit fullscreen mode

Step-by-step thinking:

  1. Server A checks: Is 10.0.2.20 in my subnet?
  2. My subnet is 10.0.1.0/24
  3. Destination starts with 10.0.2
  4. That is NOT my subnet.

So Server A says:

“I don’t know how to reach that. I’ll send it to my gateway.”

It sends traffic to:

10.0.1.1
Enter fullscreen mode Exit fullscreen mode

The router then forward it to:

10.0.2.20
Enter fullscreen mode Exit fullscreen mode

What if no gateway is set?
if you run:

ip route
Enter fullscreen mode Exit fullscreen mode

and there is NO line like:

default via 10.0.1.1
Enter fullscreen mode Exit fullscreen mode

Then:

- Server A doesn’t know where to send traffic
- You get “Network unreachable”
- Internet won’t work
Enter fullscreen mode Exit fullscreen mode

Conclusion:

"Server A cannot reach Server B because traffic to a different subnet has no route. Adding a default gateway (10.0.1.1) will resolve the issue. This is a configuration-level routing problem, not a server or network hardware issue."

Example 3: Internet Access

IP: 192.168.1.10/24
Gateway: `192.168.1.1
Destination: 8.8.8.8
Enter fullscreen mode Exit fullscreen mode

server checks:

Is 8.8.8.8 inside 192.168.1.0/24?

No.

So it sends everything to:

192.168.1.1
Enter fullscreen mode Exit fullscreen mode

That router sends it to:

  • ISP
  • Internet backbone
  • Eventually reaches 8.8.8.8

Without the gateway:

No internet.

Analysis:

  • Traffic outside local subnet is sent to gateway
  • Gateway forwards it to ISP / internet

Conclusion:

"The server requires a default gateway for internet access. Missing or misconfigured gateway causes connectivity failure. Once the gateway is correctly set, internet access is restored."

Example 4: Real Junior Troubleshooting Scenario

Problem:

"The cannot reach the database"

Database IP;

10.0.2.15
Enter fullscreen mode Exit fullscreen mode

App Server:

10.0.1.10/24
Enter fullscreen mode Exit fullscreen mode

Step 1
Check IP:

ip addr
Enter fullscreen mode Exit fullscreen mode

Confirm:

  • IP exists.
  • Interface is UP.

Step 2
Check routing:

ip route
Enter fullscreen mode Exit fullscreen mode

If you see:

default via 10.0.1.1 dev eth0
Enter fullscreen mode Exit fullscreen mode

= Good.

If you don't see default route:

= That's the issue.

Analysis:

  • The App Server is in subnet 10.0.1.0/24
  • Database Server is in subnet 10.0.2.0/24
  • Since they are on different subnets, traffic must be routed via a gateway.
  • The missing default gateway prevents the server from reaching the database.

Conclusion

"The connectivity issue is not due to IP misconfiguration or the database server being down, but due to the absence of a default gateway on the App Server."

Summary to be forwarded to Senior:

"The App Server cannot reach the Database Server because it lacks a configured default gateway. Adding the gateway 10.0.1.1 will allow traffic to flow between subnets. This is a routing configuration issue, not a network hardware or firewall problem."

Why this matters:

When someone says:

“Network is broken.”

You don’t panic.

You think:

  1. Same subnet or different?
  2. Is there a gateway?
  3. Is the gateway reachable?
  4. Is routing configured?

Summary

  • Default gateway = exit from your subnet
  • Routing = traffic decision-making
  • ip route shows routing table
  • No default route = no internet
  • Different subnet = needs routing

Today I learned that a default gateway allows my server to send traffic outside its subnet, and routing determines how packets move between networks. I practiced reading the ip route output and saw that missing or misconfigured gateways prevent communication with other subnets and the internet. I also learned how to think like a junior Platform Engineer when troubleshooting connectivity issues.
Tomorrow, I’m going to study Ports and TCP/UDP on Linux to better understand how applications communicate over the network.

Top comments (0)