Operations 12 min read

Configure Linux Routing for Dual NICs: Temporary Commands & Permanent Solutions

This guide explains how to add and delete host and network routes, set default gateways, enable IP forwarding, configure permanent routes via rc.local, sysconfig files, and static‑routes, and demonstrates a dual‑NIC experiment using VMware and eNSP to achieve simultaneous internal and external network access.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Configure Linux Routing for Dual NICs: Temporary Commands & Permanent Solutions

Linux Routing Commands

1. Add host route

route add -host 192.168.1.11 dev eth0
route add -host 192.168.1.12 gw 192.168.1.1

2. Add network route

route add -net 192.168.1.11 netmask 255.255.255.0 eth0
route add -net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1
route add -net 192.168.1.0/24 eth0
route add -net 192.168.1.0/24 gw 192.168.1.1

3. Add default gateway

route add default gw 192.168.1.1

4. Delete route

route del -host 192.168.1.11 dev eth0

5. Delete default route

route del default gw 192.168.1.1

Ways to Configure Permanent Routes in Linux

1. Add to /etc/rc.local

route add -net 192.168.1.0/24 dev eth0
# or
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

2. Append to /etc/sysconfig/network

GATEWAY=[gateway IP or interface name]

3. Use /etc/sysconfig/static-routes

any net 192.168.1.0/24 gw 192.168.1.1
# or
any net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

4. Enable IP forwarding

1. Temporary echo "1" > /proc/sys/net/ipv4/ip_forward 2. Permanent

vim /etc/sysctl.conf
# modify or add:
net.ipv4.ip_forward=1

Experiment: Configure a Dual‑NIC Host to Use Both Internal and External Networks

The experiment reproduces a real‑world scenario where a host with two network cards must access both an external ISP network (10.0.0.0/16) and an isolated internal network (172.16.0.0/16). VMware Workstation and Huawei eNSP are used to simulate the environment.

Problem Background

When the client node is the only host connecting the two networks, the internal and external networks are isolated. Placing the default gateway on the external NIC allows access to the Internet but blocks other internal subnets; placing it on the internal NIC enables full internal access but prevents Internet connectivity. The goal is to enable simultaneous access.

Experiment Environment

VMware Workstation Pro

Four minimal CentOS 7.3 virtual machines

Huawei eNSP simulator

Experiment Topology

Key nodes:

client – dual‑NIC host with IPs 10.0.0.101/16 (external) and 172.16.2.101/24 (internal)

server2 – 172.16.2.11/24

server3 – 172.16.3.11/24

server4 – 172.16.4.11/24

Network Planning

IP Allocation

client eth0   10.0.0.101   255.255.0.0   gateway 10.0.0.1   # external
client eth1   172.16.2.101 255.255.255.0           # internal
server2 eth0   172.16.2.11  255.255.255.0  gw 172.16.2.254
server3 eth0   172.16.3.11  255.255.255.0  gw 172.16.3.254
server4 eth0   172.16.4.11  255.255.255.0  gw 172.16.4.254

VMware NIC Types

Operator network – Bridged – 10.0.0.0/16
VMnet2 – Host‑only – 172.16.2.0/24
VMnet3 – Host‑only – 172.16.3.0/24
VMnet4 – Host‑only – 172.16.4.0/24

Configure Internal Network (eNSP Router)

Set interfaces on the Huawei router:

<huawei>system-view
[int g0/0/0]
ip address 172.16.2.254 255.255.255.0
[int g0/0/1]
ip address 172.16.3.254 255.255.255.0
[int g0/0/2]
ip address 172.16.4.254 255.255.255.0

Enable IP Forwarding on the Client

Temporary: echo "1" > /proc/sys/net/ipv4/ip_forward Permanent (edit /etc/sysctl.conf):

net.ipv4.ip_forward=1

Testing Connectivity

Ping external site: ping www.baidu.com -c 4 Ping each internal server:

ping 172.16.2.11 -c 4
ping 172.16.3.11 -c 4
ping 172.16.4.11 -c 4

Access HTTP services hosted on the internal servers (Python SimpleHTTPServer on port 8080):

curl http://172.16.2.11:8080/index.html
curl http://172.16.3.11:8080/index.html
curl http://172.16.4.11:8080/index.html

Adding a Persistent Route for the Whole Internal Network

On the client, add a static route covering the remaining internal subnets: route add -net 172.16.0.0/16 gw 172.16.2.254 To make it permanent, place the same command in /etc/rc.local.

Result

After adding the route, the client can reach the Internet and all internal subnets (172.16.2.0/24, 172.16.3.0/24, 172.16.4.0/24) simultaneously. The experiment demonstrates that a single static route can solve the dual‑NIC routing problem, while also illustrating the underlying routing principles.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxroutingDual NICstatic routesNetwork ConfigurationIP forwarding
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.