6

I've got 2 PCs connected on an Ethernet crossover cable. On PC1 I run:

sudo ip addr add 192.168.2.1 peer 192.168.2.2 dev eth0
sudo ip link set dev eth0 up

On PC2 I run:

sudo ip addr add 192.168.2.2 peer 192.168.2.1 dev eth0
sudo ip link set dev eth0 up
sudo ip route add default via 192.168.2.1

What's the cleanest way to replicate this set up in the interfaces(5) config file, so I can run ifup(8) instead of configuring each interface manually?

I'm on Linux Mint 15, if it matters, but I'd think it'd be the same in any Debian-based distro.

5

Here's the interfaces(5) "native" way to describe a point-to-point connection (written for PC2):

iface eth0 inet static
    address 192.168.2.2
    pointopoint 192.168.2.1
    gateway 192.168.2.1

It's also useful to know that in a pinch, if you have an unusual configuration that interfaces(5) doesn't support, you can tell it to run exactly your set of commands:

iface eth0 inet manual
    up ip link set eth0 up
    up ip addr add 192.168.2.2 peer 192.168.2.1 dev eth0
    up ip route add default via 192.168.2.1
    down ip route del default via 192.168.2.1
    down ip addr del 192.168.2.2 peer 192.168.2.1 dev eth0
    down ip link set eth0 down

This way is more error-prone, of course, and in this instance it's unnecessary. But you can also add up and down to non-manual definitions, if you want to tweak a standard setup.

  • 3
    If anyone else is wondering: pointopoint isn't a typo. – n.st Dec 3 '13 at 14:15
2

Strictly speaking, you don't need to do the peer or point to point, or gateway if all you want is to be able to communicate between these two machines.

PC1:

iface eth0 inet static
    address 192.168.2.1/24

PC2:

iface eth0 inet static
    address 192.168.2.2/24

And they should be able to ping each other. You could also specify the netmask on it's own line instead of using the /24 type notation:

address 192.168.2.1
netmask 255.255.255.0

You only need the gateway stuff in one of the machines is going to act as a router for the other machine and forward traffic to some other network it may be on.

  • This would work too. I only use pointopoint because it is conceptually a simpler model and designed for cases like this. It also has ever so slightly less overhead (not that it matters for a patch cable between 2 PCs). As for the gateway, in this case I do want PC2 to route out PC1, otherwise you raise a good point. – Michael Kropat Dec 3 '13 at 17:03
  • I'd be curious to see the differences in latency with ping between the point-to-point and the private network way. I've been using the private network way just out of laziness! – Joseph Santaniello Dec 3 '13 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.