Configuring Static and Persistent Routes in Linux and Dual‑NIC Experiment
The article explains how to configure static and persistent routes on a Linux host using the route command, make them survive reboots via rc.local, sysconfig files, or sysctl, enable IP forwarding, and demonstrates a dual‑NIC experiment where a single static route lets the client access both external and multiple internal subnets.
This article demonstrates how to configure static routes on a Linux host using the route command, how to make those routes permanent, and how to enable IP forwarding.
Linux routing commands
Add host routes:
route add -host 192.168.1.11 dev eth0
route add -host 192.168.1.12 gw 192.168.1.1Add network routes:
route add -net 192.168.1.11 netmask 255.255.255.0 eth0
route add -net 192.168.1.0/24 eth0
route add -net 192.168.1.0/24 gw 192.168.1.1Add default gateway:
route add default gw 192.168.1.1Delete routes:
route del -host 192.168.1.11 dev eth0
route del default gw 192.168.1.1Making routes persistent
Four common methods are shown:
Append commands to /etc/rc.local
Set GATEWAY= in /etc/sysconfig/network
Add entries to /etc/sysconfig/static-routes
Enable IP forwarding (temporary: echo "1" > /proc/sys/net/ipv4/ip_forward ; permanent: edit /etc/sysctl.conf and set net.ipv4.ip_forward=1 )
Experiment: dual‑NIC host accessing both internal and external networks
Environment: VMware Workstation Pro, four minimal CentOS 7.3 VMs, Huawei eNSP simulator. The topology includes an external network (10.0.0.0/16), an internal network (172.16.0.0/16), a client with two NICs (10.0.0.101/16 and 172.16.2.101/24), and three internal servers (172.16.2.11, 172.16.3.11, 172.16.4.11). The internal router is configured via eNSP and the following Huawei CLI commands:
<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.0Static routes are added on the client to reach the whole internal network:
route add -net 172.16.0.0/16 gw 172.16.2.254Permanent addition can be placed in /etc/rc.local .
Verification steps include checking the routing table, pinging external sites (e.g., ping www.baidu.com -c 4 ) and internal servers, and accessing HTTP services hosted on the servers via curl . The results show that after adding the single static route, the client can reach both external and all internal subnets.
The article concludes that a single static route solves the dual‑NIC routing problem, while the underlying principles of routing tables and default gateways are explained.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
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.