How to Route Through Two NICs on Linux
Set up a Linux computer with two network cards if you want to use the computer as a simple router for forwarding traffic between two network subnets. After the network cards are installed, the Linux kernel's IP-forwarding feature must be enabled or traffic will not be forwarded between the two subnets. Enable the Linux kernel IP-forwarding feature from the command-line terminal using the Vi and Echo Linux command-line tools.
Things You'll Need
- Password for the Root account on the Linux computer
- Linux computer with two network cards installed and connected to different subnets
- IP address of a network host on each subnet
- Command-line terminal access to a network host on each subnet
Instructions
-
-
1
Open a command-line terminal window on the Linux computer.
-
2
Type "echo 1 > /proc/sys/net/ipv4/ip_forward" without quotes at the command prompt and press the "Enter" key. If an error appears in the command line output enter "sudo echo 1 > /proc/sys/net/ipv4/ip_forward" on the command line and tap the "Enter" key. Type the Root password on the command line if prompted and press the "Enter" key.
-
-
3
Enter "vi /etc/sysctl.conf" without quotes at the command prompt and tap the "Enter" key. Scroll down to the "net.ipv4.ip_forward = 0" line in the text document that appears using the arrow keys and locate the cursor at the end of the "net.ipv4.ip_forward = 0" line.
-
4
Tap the "I" key once and then press the "Backspace" key once to delete the "0" at the end of the "net.ipv4.ip_forward = 0" line. Type "1" in the space where the "0" was located.
-
5
Press the "Esc" key and then type ":wq" and touch the "Enter" key to save the changes and exit the text document.
-
6
Open a command-line terminal on a network host connected to a subnet shared by the Linux computer. Type "ping x.x.x.x" at the command prompt except replace "x.x.x.x" with the IP address of a network host connected to the other subnet shared by the Linux computer. Press the "Enter" key and verify that replies are received and displayed on the command line output.
-
7
Repeat the previous step on a network host connected to the other subnet shared by the Linux computer to verify that traffic is being forwarded through the Linux computer between subnets in both directions.
-
1
Tips & Warnings
If IPTables or another firewall is enabled on the Linux computer, the firewall may have to be configured to allow traffic between subnets prior to performing the ping test.
References
- Photo Credit Comstock/Comstock/Getty Images