Panel For Example Panel For Example Panel For Example

Linux Default Gateway and Dual NIC Configuration

Author : Adrian September 16, 2025

Find Default Gateway IP Address in Linux And Unix

Introduction

The default gateway is a TCP/IP configuration that specifies the IP address of a directly reachable router. Setting a default gateway creates a fallback route in the IP routing table. A host can have multiple gateways configured, but the default gateway is used when the host cannot find a more specific route for a packet. If a computer's default gateway is configured incorrectly, packets can be sent to a non-router host and communication with other networks will fail. Default gateway configuration can be done manually or automatically.

Assigning IPs on Linux

Setting IP addresses on a Linux system is a basic system administrator task, but different network topologies require different approaches.

1. Single Network Interface

For a single NIC, set the address, netmask, and gateway and then restart networking. For example, using the appropriate distro network configuration tools or commands such as ifconfig/ip and restarting the network service.

2. Two Network Interfaces

a) One Gateway

If one network segment should be the path to the internet, configure one NIC with the gateway and leave the other without a gateway. Outbound traffic will use the NIC with the gateway, while the host can still communicate with devices on the other segment. This setup is common when Linux is used as a router or proxy gateway.

b) Two Gateways

If the host is connected to two different segments and both segments must reach other networks, setting a single default gateway on either NIC can break connectivity for the other segment. In this situation, ensure each NIC has the correct IP for its connected segment and use the route command to add specific routes for other networks. Example:

Set default gateway:

route add default gw 224.224.224.224 eth0

Add a network route:

route add -net 192.168.115.0/24 gw 192.168.1.254 eth1

When adding a route, you specify the next hop reachable from the local machine. The next hop must be a gateway that is directly reachable on one of the NICs.

c) Three Network Interfaces

Similar to the two-NIC case. If a network segment must access the internet through two different networks and Linux sits between them, techniques like iptables-based policy routing based on source IP ranges are typically used to direct traffic appropriately.

Example: Embedded Linux with Two NICs on Different Segments

Environment: Host runs a trimmed embedded Linux, the other host is a PC.

Two NICs on different subnets (for example, NIC A: 192.168.0.11, NIC B: 192.168.1.22). The routing table would normally have a default route and per-subnet entries. Traffic chooses the outgoing NIC based on the routing table.

Two NICs on the Same Subnet

If both NICs are in the same subnet (for example, 192.168.1.11 and 192.168.1.22), the system still has one default route. Although both IPs may appear reachable, issues arise due to ARP and routing behavior. For example, if the default route points to NIC A and NIC A is disconnected, external hosts may still ARP for both IPs and associate both IPs to the MAC of NIC A, causing connectivity problems until the default route is updated or the interface is administratively brought down.

To avoid this, use policy routing with iproute2 to assign each IP and subnet to separate routing tables, and then add rules based on source address. Example:

echo "210 local100" >> /etc/iproute2/rt_tables echo "220 local200" >> /etc/iproute2/rt_tables ip route add 192.168.1.0/24 dev wlo0 src 192.168.1.11 table local100 ip route add 192.168.1.0/24 dev eno1 src 192.168.1.22 table local200 ip route add default dev wlo0 table local100 ip route add default dev eno1 table local200 ip rule add from 192.168.1.11 table local100 ip rule add from 192.168.1.22 table local200 ip route flush cache

After this configuration, remote hosts will reach the machine using different MACs depending on the destination IP, and the system will prefer the routing table with the smallest numeric ID when multiple tables could apply. If one NIC is unplugged, the system can switch to the other NIC as the route source according to the policy rules.

Dual Network Interface Card Uses

A dual network interface card integrates two independent network ports on a single card and can connect to two different networks. Common uses include:

Network isolation: Connect one port to a public network and the other to a private network to prevent exposing internal resources while allowing controlled external access.

Performance and redundancy: Connect ports to different switches to implement load balancing and redundancy, increasing throughput and availability.

Virtualization: Use virtual networking to split a physical NIC into multiple virtual interfaces for virtual machines, providing isolated network addresses per VM.

Dual NICs are widely used in servers, firewalls, and routers for scenarios such as load balancing, redundancy, network isolation, and virtualization.

About Having Two Default Gateways

Typically, a host cannot have two default gateways. The default gateway is a single route for packets without a more specific match.

To make a host effectively use two different gateways for different destination networks, configure one NIC with the default gateway and add static routes for the other network segments to be routed via the second NIC. On Windows, route examples include:

route add -p 10.0.0.0 mask 255.255.255.0 10.40.4.200 route add -p 10.0.0.0 mask 255.0.0.0 10.40.4.200 route add -p 0.0.0.0 mask 0.0.0.0 10.40.4.200

The -p flag makes the route persistent across reboots. Use route print (Windows) or ip route (Linux) to inspect the routing table and adjust routes as needed. To remove default routes on Windows:

route delete 0.0.0.0