Configuring a Dual‑NIC Linux Server with Static Routing and Persistent Startup
This guide explains how to configure a Linux server with two network interfaces—one for an internal private network and one for external access—by setting static IPs, adding a static route, and ensuring the configuration persists across reboots using rc.local.
This article describes the steps required to set up a Linux server that connects both to an internal private network and to an external network using two Ethernet cards (eth0 and eth1). The goal is to allow users on the internal network to access external services without switching networks while keeping the traffic isolated for security.
Network interface configuration
Configure the external interface (eth0) with a static IP address:
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.0.2
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
ONBOOT=yes
TYPE=EthernetConfigure the internal interface (eth1) similarly:
DEVICE=eth1
BOOTPROTO=static
IPADDR=192.168.254.2
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=EthernetAfter applying these files (e.g., /etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/sysconfig/network-scripts/ifcfg-eth1 ), restart the network service or reboot the server.
Routing verification
Check the kernel routing table with:
route -nInitially, a default route points to the external gateway, causing return traffic from the internal network to be sent out via eth0.
Adding a static route
To force traffic destined for the internal network to leave through eth1, add a host route:
route add -host 192.168.254.1 dev eth1Verify the route works by pinging the internal gateway:
ping 192.168.254.1The ping should succeed, confirming that packets are now routed correctly.
Persisting the route
Because the static route disappears after a reboot, add the command to /etc/rc.d/rc.local (or the appropriate startup script) so it runs on boot:
#!/bin/sh
# Add static route for internal network
/sbin/route add -host 192.168.254.1 dev eth1Make the script executable ( chmod +x /etc/rc.d/rc.local ) and ensure it is enabled.
Important notes
Do not set a GATEWAY entry in both ifcfg-eth0 and ifcfg-eth1 ; having two gateways can cause unpredictable routing behavior.
If the server’s firewall blocks the ping, stop the firewall temporarily with service iptables stop (or adjust the rules) to test connectivity.
When adding the route in rc.local , use the full path to the route binary (e.g., /sbin/route ) to avoid “command not found” errors.
Following these steps results in a dual‑NIC Linux server that securely bridges the internal and external networks while maintaining persistent routing configuration.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.