How to connect two Linux machines, each with two Ethernet cards, together on their own private network

I have two machines, one connected to one ISP, the other connected to another ISP. Both machines have two Ethernet cards (aka NIC cards). I want to connect the two machines directly together so that traffic back and forth between them can go direct, rather than from one ISP to the other. How? Easy!

First, connect the second Ethernet card in each machine with a crossover cable. This is a regular Ethernet cable but for the fact that its “send” and “receive” wires are crossed over (this is an over-simplication, but it helps). When you go to the store to buy this cable, make sure you buy a crossover cable rather than a regular patch cable. As an alternative, you can plug both machines, using regular patch cables, into the same hub; the effect is the same.

Next, set up the network connection on the first machine’s second Ethernet card:

ifconfig eth1 192.168.1.1 netmask 255.255.255.0 up
route add -net 192.168.1.0 netmask 255.255.255.0 eth1

This assigns an IP address of 192.168.1.1 to the second Ethernet connection. This IP is of a special collection set aside for this “private” purpose; just don’t pick one at random!.

Next, do the same on the second machine:

ifconfig eth1 192.168.1.2 netmask 255.255.255.0 up
route add -net 192.168.1.0 netmask 255.255.255.0 eth1

Same deal here, but this machine gets an IP address of 192.168.1.2.

That’s it! At this point you should be able to ping 192.168.1.1 from 192.168.1.2 and vice versa.

I’ve just set up a couple of machines like this for polling day here on Prince Edward Island; both of them have gigabit Ethernet cards. You wouldn’t believe how fast files fly from one to the other!

I’m posting this here because most of what you’ll Google when searching for how to do this is instructions for connecting one machine to the Internet using a second machine’s existing Internet connection, and that’s not what this is about.

I’m assuming, by the way, that you’ve already handled getting the second Ethernet cards in each machine recognized and configured as eth1.

Comments

Post new comment

You can comment anonymously if you must, but I would prefer it if you used your real name.
The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Optional. If you enter the address of a website here, your name will be publicly linked to the site.
  • Adds typographic refinements.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.