-1

I am trying to configure a few VM's network configuration and consul etc. I am using vagrant and configured the VMs to use a private network. This creates an interface eth1 in addition to the NAT connection to the host on eth0. Consul by default uses the first interface, eth0. Of course that messes everything up because both VMs register with the same IP which is not the one from the private network, but from the host connection.

So far, so good. I can change which IP consul uses, but this got me wondering:

Is there a better heuristic for finding the "main" interface than "use the first one"?

Since this is an attempt at automating network configuration and dns, I would like some kind of general solution, but I am not sure how to do this. Ideally this would be the one where the other consul-agents live. The more heterogenous such a cluster is, the less likely it is that the interface is the same for all cluster nodes.

Basically, I am looking for "do-what-i-mean(X)" for networking. ;-)

1
  • usually, if you want to avoid the OS mixing up virtual interfaces, you have the ability to tell him to recognize them by their MAC address. in red hat linux,/centos there is a "HWADDR" directive in /etc/sysconfig/networking-scripts/ifcfg-ethX.cfg
    – mveroone
    Jun 12, 2015 at 8:28

1 Answer 1

1

You can enforce consistent naming across reboots by means of udev. Actually, this was one of the major reasons (not the only one) behind the development of udev.

Suppose you have two ethernet interfaces, one with MAC aa:bb:cc:dd:ee:ff which you want to call wan0, the other one with mac address 00:11:22:33:44:55 which you wan to call local1.

Then you can edit the file /etc/udev/rules.d/70-persistent-net.rules, locating a line like this:

 # PCI device 0x8086:0x1502 (e1000e)
 SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="aa:bb:cc:dd:ee:ff", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

This rule gives to the PCI device with Vendor code 8086 and Product code 1502, and MAC address aa:bb:cc:dd:ee:ff, the name eth0. Change eth0 to wan0, and you have a rule which will always give to this NIC the same name. Likewise for the other interface.

Substitute to aa:bb:cc:dd:ee:ff above the MAC address appropriate to the interface talking to the host, and to 00:11:22:33:44:55 the MAC address of the NIC talking to the other guests, and you are done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .