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

Peter Rukavina

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.

Add new comment

Plain text

  • Allowed HTML tags: <b> <i> <em> <strong> <blockquote> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

About This Blog

Photo of Peter RukavinaI am . I am a writer, letterpress printer, and a curious person.

To learn more about me, read my /nowlook at my bio, listen to audio I’ve posted, read presentations and speeches I’ve written, or get in touch (peter@rukavina.net is the quickest way). 

You can subscribe to an RSS feed of posts, an RSS feed of comments, or a podcast RSS feed that just contains audio posts. You can also receive a daily digests of posts by email.

Search